Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

save text input to selectmenu

Ok, thank you. Will take a look.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

save text input to selectmenu

To make features you ask next steps must be implemented:

  1. Company name and company email must be saved to an array stored in localStorage variable;

  2. Select menu component must be filled with data from this localStorage variable.

    You already have "save" and "myload" JavaScript functions to save/load array in localStorage variable.

    First of all function "setSelectMenuOptions" must be rewriten to update select menu with sorted data:

    code
    function setSelectMenuOptions(select, options) {
    options.sort(function(a, b){return a.name.localeCompare(b.name);} );

    select.children().each(function() {$(this).remove()});
    for(i=0; i<options&#46;length; i++) {
    var label = options&#46;name;
    var value = options&#46;email;
    var newOption = $('<option value="'+value+'">'+label+'<&#47;option>');
    select&#46;append(newOption);
    }
    select&#46;refresh();
    }/code

    On "Save" button click JavaScript action must be added:

    code
    &#47;&#47;Save company name and email to an array stored in localStorage variable "companiesArray"&#46;
    save({'name':Tiggzi("conametextinput")&#46;val(), "email":Tiggzi("coemailtextinput")&#46;val()}, "companiesArray");
    &#47;&#47;Update select menu
    setSelectMenuOptions(Tiggzi('taxicoselectmenu'), myload("companiesArray"));
    /code

    On "Delete" button click next Javascript action must be added:

    code
    var selectedMail = Tiggzi('taxicoselectmenu')&#46;val();
    var companiesArray = myload("companiesArray");

    &#47;&#47;Search for company with selected email
    var companyIndex = -1;
    for(var i=0; i<companiesArray&#46;length; i++) {
    var comp = companiesArray;
    if(comp&#46;email == selectedMail) {
    companyIndex = i;
    }
    }

    if(companyIndex >= 0) {
    &#47;&#47;Remove element from array
    companiesArray&#46;splice(companyIndex, 1);
    &#47;&#47;Save array to localStorage variable
    localStorage&#46;setItem("companiesArray", JSON&#46;stringify(companiesArray));
    &#47;&#47;Update select menu options
    setSelectMenuOptions(Tiggzi('taxicoselectmenu'), companiesArray);
    }/code

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

save text input to selectmenu

Hi Katya,
I am back to this issue now!
you have given me 3 pieces of code and Marina has given me 2
am I to use all 5 pieces of code or the 3 pieces you have given

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

save text input to selectmenu

Hello,
These 3 pieces include 2 others so you can use the latest 3 only.

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

save text input to selectmenu

Hi Katya,
I have set the code for the save and delete button.
the following code I have as new js called "selectmenu"
its working, it saves, sorts, and deletes, but the app will not navigate to other pages since I added this code.
Can you tell me what I have done wrong?

codefunction setSelectMenuOptions(select, options) {
options&#46;sort(function(a, b){return a&#46;name&#46;localeCompare(b&#46;name);} );

select&#46;children()&#46;each(function() {$(this)&#46;remove()});
for(i=0; i<options&#46;length; i++) {
var label = options&#46;name;
var value = options&#46;email;
var newOption = $('<option value="'+value+'">'+label+'<&#47;option>');
select&#46;append(newOption);
}
select&#46;refresh();
} /code

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

save text input to selectmenu

Are there any errors in Chrome Developer console or Firebug?

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

save text input to selectmenu

Hi Katya,
I get this error

TypeError: a.name is undefined
[Break On This Error]

options.sort(function(a, b){return a.name.localeCompare(b.name);} );

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

save text input to selectmenu

The incorrect data is stored in localStorage variable.

There several solutions can exist:

  • Clear localStorage variable where array is stored using "Set local storage variable" action;

  • To clear all localStorage variables open Developers Console and run: codelocalStorage&#46;clear()/code

  • Clear browser cache.

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

save text input to selectmenu

Hi Katya,
I am sorry for all this but I am struggling on this

I have run the code above,
navigation in app is not good
the taxicoselectmenu is working but acting very strange, and the other selectmenus on a different page are now undifined (they were working)
I have shared the app

again thanks for all your help

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

save text input to selectmenu

Hello! Please first check you are using correct components name

Return to “Issues”