Announcement

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

    Invalid value caching in DynamicForm

    Hi Isomorphic,
    I'm using SC_SNAPSHOT-2011-03-08/LGPL Deployment (built 2011-03-08).
    I have a ListGrid connected with a DynamicForm (sharing the same RestDataSource) used for editing selected row (form.setData(record)).
    Values are validated with a custom server-side validator.

    The problem is that when in DynForm an improper value is provided and fails validation (formDataSource.updateData(formData) returns -4 status for some field) the improper value is saved somewhere in the form cache.
    ListGrid, that is also connected to the same DataSource doesn't show this change. Selecting other rows and going back to the one that was edited and submited (validated) doesn't change anything, the validated (improper) value is loaded into the form.

    I try to reset the form before loading it with row data, but the problem still exists.

    My code:
    RestDataSource
    Code:
    isc.RestDataSource.create({
    dataURL:"/?someURL",
    dataFormat:"json",
    dataProtocol:"postParams",
    showPrompt: false,
    ID:"groupDS",
    useLocalValidators: false,
    fields:[
    { type:"text", name:"name", title:"Example field causing problems", required: true},
    .... other fields
    ]});
    DynamicForm
    Code:
    isc.DynamicForm.create({
    	ID: "groupEdit",
    	dataSource: "groupDS",
    	layoutAlign: "center",
    	saveOperationType: "update",
    	numCols: 5,
    	colWidths: [ "20%", "30%", "20%", "10%", "20%"],
    	width: "100%", height: 100,
    	disableValidation: true,
    	fields:[
    		{ title:"Nazwa grupy", type:"text", name:"Example field causing problems", width:200 },
                    .... other fields
    	]
    });
    Update submit button
    Code:
    click: function () {
    	groupEdit.clearErrors(true);
    	groupEdit.saveData();
    }
    Thanks in advance for your help.

    #2
    Any suggestions?

    Comment


      #3
      It's not clear exactly what you are seeing and what you expect. Note there is no form cache for saving improper values.

      Comment


        #4
        What I do (one thing after another):
        - selecting record from ListGrid
        - loading it into DynamicForm for editing
        - editig it and submiting (with server side validation failing)
        - selecting another record (loading it into Form but not editing/submiting)
        - selecting the first/'edited and submited with failing validation' record

        What I see:
        - after submiting and validation failing the Form shows errors on incorrect fields with changed (incorrect) values, the LG values stay intact, thats all ok
        - when selecting different row, it's data is loaded into Form (values are the same as in the ListGrid), thats also ok
        - selecting for the second time the edited row - now the Form values are not the one from the LG but the submited ones - that's incorrect,

        What I want to have:
        - if a submit is failing for a particular row and after that I select a different one and come back to the submited one, I don't want to have the values that were submited (but server validation discarded them) loaded into the Form, but the ones that are in the LG for this record

        If it's still not clear enough I can provide screenshots of the operations.

        Comment


          #5
          Here is a simple test case:
          Code:
          testData = [
          
          {
              continent:"North America",
              countryName:"United States",
              countryCode:"US",
              area:9631420,
              population:298444215,
              gdp:12360.0,
              independence:new Date(1776,6,4),
              government:"federal republic",
              government_desc:2,
              capital:"Washington, DC",
              member_g8:true,
              article:"http://en.wikipedia.org/wiki/United_states"
          },
          {
              continent:"Asia",
              countryName:"China",
              countryCode:"CH",
              area:9596960,
              population:1313973713,
              gdp:8859.0,
              government:"Communist state",
              government_desc:0,
              capital:"Beijing",
              member_g8:false,
              article:"http://en.wikipedia.org/wiki/China"
          },
          {
              continent:"Asia",
              countryName:"Japan",
              countryCode:"JA",
              area:377835,
              population:127463611,
              gdp:4018.0,
              government:"constitutional monarchy with parliamentary government",
              government_desc:1,
              capital:"Tokyo",
              member_g8:true,
              article:"http://en.wikipedia.org/wiki/Japan"
          },
          {
              continent:"Asia",
              countryName:"India",
              countryCode:"IN",
              area:3287590,
              population:1095351995,
              gdp:3611.0,
              independence:new Date(1947,7,15),
              government:"federal republic",
              government_desc:2,
              capital:"New Delhi",
              member_g8:false,
              article:"http://en.wikipedia.org/wiki/India"
          },
          {
              continent:"Europe",
              countryName:"Germany",
              countryCode:"GM",
              area:357021,
              population:82422299,
              gdp:2504.0,
              independence:new Date(1871,0,18),
              government:"federal republic",
              government_desc:2,
              capital:"Berlin",
              member_g8:true,
              article:"http://en.wikipedia.org/wiki/Germany"
          }
          ]
          
          isc.ListGrid.create({
              ID: "countryList",
              width:500, height:224, alternateRecordStyles:true,
              data: testData,
              fields:[
                  {name:"countryCode", title:"Flag", width:50, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png"},
                  {name:"countryName", title:"Country"},
                  {name:"capital", title:"Capital", showIf:"false"},
                  {name:"continent", title:"Continent"}
              ],
              selectionChanged: function(record, isSelected) {
          	if(isSelected) {
          		editForm.setValues(record);
          	} else {
                         //editForm.resetValues();
          		editForm.setValues(editForm.getOldValues());
          		editForm.clearValues();
          	}
              },
              canReorderFields: true
          })
          
          
          isc.IButton.create({
              left:0, top:240,
              title:"Show Capitals",
              click:"countryList.showField('capital')"
          })
          
          isc.IButton.create({
              left:120, top:240,
              title:"Hide Capitals",
              click:"countryList.hideField('capital')"
          })
          
          isc.DynamicForm.create({
             ID: 'editForm',
             top: 300,
          fields: [
            {title: 'Continent', name: 'continent' }
          ]
          })
          Test:
          - select China
          - edit 'Asia' to sth else
          - select another country
          - select China once more

          Result:
          after selecting China for the second time the edited value is displayed in the edit field instead of 'Asia'

          Expected:
          after selecting China for the second time 'Asia' (value from the ListGrid) is inserted into the edit field

          Please help.

          Comment


            #6
            What's happening here is that the call to 'setValues()' is passing the record object directly to the DynamicForm where it is being directly modified as the user edts the value for the form item. Then when you de-select and reselect the record in the grid, the edited value shows up. In fact if you called 'redraw()' on the grid you'd see the edited value show up there.

            The best solution for this is to call form.editRecord(<record>) rather than using setValues() directly. Alternatively you could duplicate the record when you pass it into set values via form.setValues(isc.addProperties({},record));

            Comment


              #7
              Originally posted by Isomorphic
              What's happening here is that the call to 'setValues()' is passing the record object directly to the DynamicForm where it is being directly modified as the user edts the value for the form item. Then when you de-select and reselect the record in the grid, the edited value shows up. In fact if you called 'redraw()' on the grid you'd see the edited value show up there.

              The best solution for this is to call form.editRecord(<record>) rather than using setValues() directly. Alternatively you could duplicate the record when you pass it into set values via form.setValues(isc.addProperties({},record));
              Thanks a lot. Now it works perfectly.

              Comment

              Working...
              X