Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to avoid saving all fields in DynamicForm to the database

    Hello there,

    I am using SmartClient Version: v10.0p_2015-05-08/PowerEdition Deployment (built 2015-05-08) with FF26.

    I am displaying a listgrid and a Dynamic form in a VLayout. In the DynamicForm the user will enter/choose some data and save. The listgrid displays the records saved in the form.
    The problem I have is in the DynamicForm some of the data(GTINA,GTINB see code below) are read only and need not be saved to the DB. But now it is saving to the db table. How can tell SmartClient not to save those fields to the db.
    In the listgrid I am able to not show those two fields by NOT defining the ListGridField for those fields. But in the DynamicForm I need to display them but not save it to the db.

    Code:
    final DataSource ds3 = DataSource.get("productDS");
    final SelectItem product = new SelectItem("idp");
    product.setOptionDataSource(ds3);
    product.setDisplayField("name");
    
    final TextItem GTINA = new TextItem("upck");
    GTINA.setCanEdit(false);
    
    final TextItem GTINB = new TextItem("puck");
    GTINB.setCanEdit(false);
    
    TextItem batchNo = new TextItem("thc");
    
    product.addChangedHandler(new ChangedHandler()
    		{
    			@Override
    			public void onChanged(ChangedEvent event)
    			{
    				Integer productID = (Integer) product.getValue();
    				Criteria criteria = new Criteria();
    				criteria.addCriteria("id", productID);
    				ds3.fetchData(criteria, new DSCallback()
    				{
    					public void execute(DSResponse response, Object rawData, DSRequest request)
    					{
    						Record[] records = response.getData();
    						for (Record record : records)
    						{
    							GTINA.setValue(record.getAttribute("supck"));
    							GTINB.setValue(record.getAttribute("mupck"));
    						}
    					}
    				});
    
    			}
    		});
    
    orderForm.setItems(dosageForm, product, GTINA, GTINB, batchNo, mfgDate, expDate, distributor);
    Datasource file

    Code:
    <DataSource ID="newOrderDS" serverType="sql" tableName="rde">
     	<fields>
    		<field name="id" type="sequence" hidden="true" primaryKey="true" />        
    		<field name="dfid" title="Dosage Form" type="integer" foreignKey="dosformDS.id" joinType="outer" displayField = "dosageformName" required="true">
    		</field>
    		<field name="dosageformName" includeFrom="dosformDS.name" hidden="true" />		
    		<field name="idp" title="Product" type="integer" foreignKey="productDS.id" joinType="outer" displayField = "productName" required="true">
    		</field>
    		<field name="productName" includeFrom="productDS.name" hidden="true" />	     
    		<field name="upck" title="GTIN A Order Quantity" type="integer"/>
    		<field name="puck" title="GTIN B Order Quantity" type="integer"/>		
    		<field name="thc" title="Batch Number" type="text" required="true"/>		
    		<field name="date1" title="Manufacturing Date" type="date" required="true"/>		
    		<field name="date2" title="Expiry Date" type="date" required="true"/>	
    		<field name="dip" title="Distributor" type="integer" foreignKey="distributorDS.id" joinType="outer" displayField = "distributorName" required="false">
    		</field>
    		<field name="distributorName" includeFrom="distributorDS.name" hidden="true" />		
    		<field name="sden" type="boolean" title="Send"/>	
    		<field name="port" type="boolean"/>
    	</fields>
    </DataSource>

    #2
    Ah yes - you're setting 'canEdit' to false which disallows the user from editing the field, but by setting the value programmatically you're still getting it into the "values" object for the form.

    You could achieve this a couple of ways
    - One option would be to have your saving logic call 'getValues' on the form, then duplicate that object, omitting the fields you want to leave client-side, and then call the appropriate DataSource databinding API (probably 'updateValue') on the DataSource directly with that object.
    - Another option would be, rather than having items in your form with fieldNames which match the fields in your dataSource, have them with a different name such as "upck_display", and call 'setShouldSaveValue(false)' on these items.
    Then you can populate them directly in your code, but they'll never be part of the 'values' object that gets saved to the server through the normal databinding flow.

    Regards
    Isomorphic Software

    Comment


      #3
      Hi Isomporhic,

      Thanks for your comments.

      Comment

      Working...
      X