appmaker - Want To Copy Certain Fields From Previous Entry To New Fragment -


short version: want have copy button in table able grab values existing entry , populate "create entry" page fragment. way users don't have reenter data when making new entry.


long version:

i have 2 buttons added rows in table: edit , copy.

enter image description here

the edit button uses following code grab information specific row , uses fragment edit entry.

widget.datasource.savechanges(); app.datasources.systemorders.selectkey(widget.datasource.item._key); app.showdialog(app.pagefragments.systemorders_edit); 

the copy button using following code duplicate entry , automatically create it.

//allows copying table/row var rowdatasource = widget.datasource; var listdatasource = app.datasources.systemorders_hidecomplete; var createdatasource = listdatasource.modes.create;  widget.datasource.savechanges();  // enter fields want duplicate below createdatasource.item.projectname = rowdatasource.item.showname; createdatasource.item.deliveryinfo = rowdatasource.item.deliveryinfo; createdatasource.item.sob = rowdatasource.item.sob; createdatasource.item.deliverydate = rowdatasource.item.deliverydate; createdatasource.item.company = rowdatasource.item.company; createdatasource.item.location = rowdatasource.item.location;  createdatasource.item.additionalperipherals = rowdatasource.item.additionalperipherals; createdatasource.item.notes = rowdatasource.item.notes; createdatasource.createitem(); 

i change behavior copy button grab values specific fields, instead of doing createdatasource/createitem(); want place values page fragment (ex: systemorders_add) has corresponding fields.

this way user can click "copy" , systemorders_add fragment appears pre-populated values.

i want make sure these values in page fragment , not commited until user presses submit button.

newsoemailmessage(widget); widget.datasource.createitem(); app.closedialog(); 

thank help!

one way can accomplish passing data custom properties defined in page fragment , can place properties corresponding fields. recommend check article https://developers.google.com/appmaker/ui/viewfragments#use_custom_properties_to_customize_page_fragments

first need create custom properties inside page fragment. in copy button onclick event can use save row data table custom properties:

var rowdatasource = widget.datasource.item._key; app.datasources.systemorders.selectkey(rowdatasource);  var projectname = app.datasources.systemorders.item.project_name; var deliveryinfo = app.datasources.systemorders.item.delivery_info; //... app.pagefragments.systemorders_edit.properties.projectname = projectname; app.pagefragments.systemorders_edit.properties.deliveryinfo = deliveryinfo; //... app.showdialog(app.pagefragments.systemorders_edit); 

assuming have form inside page fragment, can bind value of each field custom properties. binding ensure data pre-populated. can done each field via property editor , binding should this: @properties.projectname

inside submit button onclick event can use create new item in datasource using values available in each field.

var projectname = widget.root.descendants.field1.value; var deliveryinfo = widget.root.descendants.field2.value; //...  var mydatasource = app.datasources.systemorders_hidecomplete; var mycreatedatasource = mydatasource.modes.create; var draft = mydatasource.modes.create.item;     draft.project_name = projectname;    draft.delivery_info = deliveryinfo;    //...     // create new item    mycreatedatasource.createitem();  app.closedialog(); 

you can set properties null once item created (maybe ondetach) this: app.pagefragments.systemorders_edit.properties.projectname = null;

hope helps!


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -