save text input to selectmenu
Ok, thank you. Will take a look.
Catch up wih the Appery.io community on our forum. Here you'll find information on the lastest questions and issues Appery.io developers are discussing.
https://forum.appery.io/
Ok, thank you. Will take a look.
To make features you ask next steps must be implemented:
Company name and company email must be saved to an array stored in localStorage variable;
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.length; i++) {
var label = options.name;
var value = options.email;
var newOption = $('<option value="'+value+'">'+label+'</option>');
select.append(newOption);
}
select.refresh();
}/code
On "Save" button click JavaScript action must be added:
code
//Save company name and email to an array stored in localStorage variable "companiesArray".
save({'name':Tiggzi("conametextinput").val(), "email":Tiggzi("coemailtextinput").val()}, "companiesArray");
//Update select menu
setSelectMenuOptions(Tiggzi('taxicoselectmenu'), myload("companiesArray"));
/code
On "Delete" button click next Javascript action must be added:
code
var selectedMail = Tiggzi('taxicoselectmenu').val();
var companiesArray = myload("companiesArray");
//Search for company with selected email
var companyIndex = -1;
for(var i=0; i<companiesArray.length; i++) {
var comp = companiesArray;
if(comp.email == selectedMail) {
companyIndex = i;
}
}
if(companyIndex >= 0) {
//Remove element from array
companiesArray.splice(companyIndex, 1);
//Save array to localStorage variable
localStorage.setItem("companiesArray", JSON.stringify(companiesArray));
//Update select menu options
setSelectMenuOptions(Tiggzi('taxicoselectmenu'), companiesArray);
}/code
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
Hello,
These 3 pieces include 2 others so you can use the latest 3 only.
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.sort(function(a, b){return a.name.localeCompare(b.name);} );
select.children().each(function() {$(this).remove()});
for(i=0; i<options.length; i++) {
var label = options.name;
var value = options.email;
var newOption = $('<option value="'+value+'">'+label+'</option>');
select.append(newOption);
}
select.refresh();
} /code
Are there any errors in Chrome Developer console or Firebug?
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);} );
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.clear()/code
Clear browser cache.
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
Hello! Please first check you are using correct components name