Hi Isomorphic,
please see this builtInDS based testcase (v10.0p_2015-04-30, FF26 dev mode):
BuiltInDS.java:
supplyItem.ds.xml (removed sequence, removed invalid FK):
Start the sample and hit "Save" twice to see the effect (also included as screenshot). Observations:
- This does not happen if the PK-FormItem itemID is a HiddenItem instead of a FormItem.
- On reload after save (when the fetch returns data), the correct action of UPDATE is triggered on save-button hit.
Best regards
Blama
please see this builtInDS based testcase (v10.0p_2015-04-30, FF26 dev mode):
BuiltInDS.java:
Code:
package com.smartgwt.sample.client; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.core.KeyIdentifier; import com.smartgwt.client.data.AdvancedCriteria; import com.smartgwt.client.data.Criterion; import com.smartgwt.client.data.DSCallback; import com.smartgwt.client.data.DSRequest; import com.smartgwt.client.data.DSResponse; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.types.OperatorId; import com.smartgwt.client.util.PageKeyHandler; import com.smartgwt.client.util.Page; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.HiddenItem; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VStack; public class BuiltInDS implements EntryPoint { private DynamicForm boundForm; private FormItem itemID; private IButton saveBtn; private IButton cancelBtn; public void onModuleLoad() { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new PageKeyHandler() { public void execute(String keyName) { SC.showConsole(); } }); VStack vStack = new VStack(); vStack.setLeft(175); vStack.setTop(75); vStack.setWidth("70%"); vStack.setMembersMargin(20); boundForm = new DynamicForm(); boundForm.setDataSource(DataSource.get("supplyItem")); itemID = new FormItem("itemID"); FormItem itemName = new FormItem("itemName"); itemName.setDefaultValue("Default name that might be OK"); FormItem sku = new FormItem("SKU"); sku.setDefaultValue("DefaultOK"); FormItem category = new FormItem("category"); category.setDefaultValue("Default category that might be OK"); FormItem unitCost = new FormItem("unitCost"); unitCost.setDefaultValue(42); boundForm.setFields(itemID, itemName, sku, category, unitCost); boundForm.fetchData(new AdvancedCriteria(new Criterion("itemID", OperatorId.EQUALS, 10004)), new DSCallback() { @Override public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) { if (dsResponse.getStatus() == DSResponse.STATUS_SUCCESS && dsResponse.getTotalRows() == 1) boundForm.rememberValues(); else if (dsResponse.getStatus() == DSResponse.STATUS_SUCCESS && dsResponse.getTotalRows() == 0) { boundForm.rememberValues(); itemID.setValue(10004); SC.say("PK value set via code"); } } }); vStack.addMember(boundForm); HLayout hLayout = new HLayout(10); hLayout.setMembersMargin(10); hLayout.setHeight(22); saveBtn = new IButton("Save"); saveBtn.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { boundForm.saveData(); } }); hLayout.addMember(saveBtn); cancelBtn = new IButton("Status?"); cancelBtn.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (boundForm.valuesHaveChanged()) { SC.say("Values have changed"); // boundForm.resetValues(); } else SC.say("Values have not changed"); } }); hLayout.addMember(cancelBtn); vStack.addMember(hLayout); vStack.draw(); } }
Code:
<DataSource ID="supplyItem" serverType="sql" tableName="supplyItem" titleField="itemName" testFileName="/examples/shared/ds/test_data/supplyItem.data.xml" dbImportFileName="/examples/shared/ds/test_data/supplyItemLarge.data.xml"> <fields> <field name="itemID" type="integer" hidden="true" primaryKey="true" /> <field name="itemName" type="text" title="Item" length="128" required="true" /> <field name="SKU" type="text" title="SKU" length="10" required="true" /> <field name="description" type="text" title="Description" length="2000" /> <field name="category" type="text" title="Category" length="128" required="true" /> <field name="units" type="enum" title="Units" length="5"> <valueMap> <value>Roll</value> <value>Ea</value> <value>Pkt</value> <value>Set</value> <value>Tube</value> <value>Pad</value> <value>Ream</value> <value>Tin</value> <value>Bag</value> <value>Ctn</value> <value>Box</value> </valueMap> </field> <field name="unitCost" type="float" title="Unit Cost" required="true"> <validators> <validator type="floatRange" min="0" errorMessage="Please enter a valid (positive) cost" /> <validator type="floatPrecision" precision="2" errorMessage="The maximum allowed precision is 2" /> </validators> </field> <field name="inStock" type="boolean" title="In Stock" /> <field name="nextShipment" type="date" title="Next Shipment" /> </fields> </DataSource>
- This does not happen if the PK-FormItem itemID is a HiddenItem instead of a FormItem.
- On reload after save (when the fetch returns data), the correct action of UPDATE is triggered on save-button hit.
Best regards
Blama
Comment