Announcement

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

    form resetValues

    Hi,

    I'm putting some initial values in a form,
    call rememberValues()
    then change the item on screen (user input)
    then do a resetValues() which should revert to the initial values, right?

    When I hit my button, the item isn't being reset anymore.

    Code:
    public void test17() {
    	final DynamicForm form = new DynamicForm();
    	TextItem f1 = new TextItem();
    	f1.setName("remember");
    	form.setFields(f1);
    	
    	Map initialValues = new LinkedHashMap();
    	initialValues.put("remember", "me");
    	form.editNewRecord(initialValues);
    	form.rememberValues();
    	
    	Button reset = new Button("Reset Values");
    	reset.addClickHandler(new ClickHandler() {
    		
    		public void onClick(ClickEvent event) {
    			form.reset();
    			form.resetValues();
    			form.clearErrors(true);
    		}
    	});
    	
    	
    	VLayout layout = new VLayout();
    	layout.setWidth100();
    	layout.setHeight(600);
    	layout.setMembers(form, reset);
    	masterPanel.addChild(layout);
    }

    SmartClient Version: SC_SNAPSHOT-2012-01-15_v8.3d/Pro Deployment (built 2012-01-15)

    thanks,

    #2
    You're right. This was a very recent regression in the 8.3 dev branch - will be fixed in the next nightly build.
    Sorry for the inconvenience

    Comment


      #3
      Thanks for the quick action.
      Verified this case with SC_SNAPSHOT-2012-01-18_v8.3d/Pro Deployment (built 2012-01-18) and it's fixed.
      However using this build in my target application, nothing appears to be working :/ I don't see any value in a form or even a simple thing as a static text item isn't showing anything.
      Tried restarting and cleaning Eclipse & browser a few times. I'll try another nightly next week.

      Comment


        #4
        That sounds quite alarming! Unfortunately it doesn't give us much to go on (presumably you're not saying that all form values are broken in general - it's something specific to do with your target application)?

        If things are as broken as you indicate for your use-case, it'd probably be best to show us a simple standalone test case demonstrating the problem so we can see what is going wrong.

        As an aside - we are doing some work in the area of values management, specifically to do with handling of dataPaths (an area we believe you are making use of). This work is not complete - further changes are in progress, but existing behavior should not have been broken by this work, so we'd definitely like to see the problems so if changes need to be made we can address them.

        Comment


          #5
          From your reaction, you sounded really surprised, so I had another go with the 19/01/2012 build and I got the same problem in my app. I don't have it in another standalone project, so I tried to pinpoint the problem by eliminating some things we do differently, and after deep digging, I found the problem in some custom JS of ours.
          Sorry about that!

          Comment


            #6
            Hi,
            I'm trying to do the same with a valuesManager and a single dataPath with 2 forms.

            repro:
            click "set defaults"
            change some values in the fields
            click "reset"
            <= the default values are not reset


            Code:
            private DataSource getDS() {
            	DataSourceField pkField = new DataSourceField();
            	pkField.setName("pk");
            	pkField.setPrimaryKey(true);
            	pkField.setType(FieldType.SEQUENCE);
            	pkField.setHidden(true);
            
            	DataSourceField testField = new DataSourceField();
            	testField.setName("field1");
            	testField.setType(FieldType.TEXT);
            	testField.setCanEdit(true);
            	
            	DataSourceField testField2 = new DataSourceField();
            	testField2.setName("field2");
            	testField2.setType(FieldType.TEXT);
            	testField2.setCanEdit(false);
            	
            	DataSourceField testField3 = new DataSourceField();
            	testField3.setName("field3");
            	testField3.setType(FieldType.TEXT);
            	testField3.setCanEdit(true);
            	
            	DataSourceField testField4 = new DataSourceField();
            	testField4.setName("field4");
            	testField4.setType(FieldType.TEXT);
            	testField4.setCanEdit(true);
            	testField4.setRequired(true);
            
            	DataSource testDS = new DataSource();
            	testDS.setFields(pkField, testField, testField2, testField3, testField4);
            	testDS.setClientOnly(true);
            	
            	ListGridRecord[] testData = new ListGridRecord[] { new ListGridRecord() {
            		{
            			setAttribute("pk", 0);
            			setAttribute("field1", "Value 1");
            			setAttribute("field2", "Value 2");
            			setAttribute("field3", "Value 3");
            			setAttribute("field4", "");
            		}
            	} };
            	testDS.setTestData(testData);
            	
            	return testDS;
            }
            
            private DataSource getSessDS(String dataPath) {
            	DataSourceField pkField = new DataSourceField();
            	pkField.setName("pk");
            	pkField.setPrimaryKey(true);
            	pkField.setType(FieldType.SEQUENCE);
            	pkField.setHidden(true);
            	
            	DataSourceField subDSField = new DataSourceField();
            	subDSField.setName(dataPath);
            	subDSField.setTypeAsDataSource(getSubDS());
            	
            	DataSource testDS = new DataSource();
            	testDS.setFields(pkField, subDSField);
            	testDS.setClientOnly(true);
            	
            	return testDS;
            }
            
            public void test20() {
            	final ValuesManager vm = new ValuesManager();
            	final String dataPath = "/args";
            	vm.setDataSource(getSessDS("args"));
            	
            	DynamicForm f1 = new DynamicForm();
            	f1.setDataPath(dataPath);
            	f1.setWidth(300);
            	f1.setHeight(100);
            	FormItem field1 = new FormItem();
            	field1.setDataPath(dataPath + "/field1");
            	FormItem field2 = new FormItem();
            	field2.setDataPath(dataPath + "/field2");
            	f1.setFields(field1, field2);
            	vm.addMember(f1);
            	
            	
            	
            	DynamicForm f2 = new DynamicForm();
            	f2.setDataPath(dataPath);
            	f2.setWidth(300);
            	f2.setHeight(100);
            	FormItem field3 = new FormItem();
            	field3.setDataPath(dataPath + "/field3");
            	FormItem field4 = new FormItem();
            	field4.setDataPath(dataPath + "/field4");
            	f2.setFields(field3, field4);
            	vm.addMember(f2);
            	
            	IButton setDefs = new IButton("set default values via VM");
            	setDefs.addClickHandler(new ClickHandler() {
            		
            		public void onClick(ClickEvent event) {
            			
            			//How to specify as map??
            //				Map initialValues = new LinkedHashMap();
            //				initialValues.put(dataPath + "/field1", "def1");
            //				initialValues.put(dataPath + "/field3", "def3");
            //				vm.editNewRecord(initialValues);
            			
            			
            			Record r = new Record();
            			JavaScriptObject jso = JSOHelper.createObject();
            			JSOHelper.setAttribute(jso, "field1", "def1");
            			JSOHelper.setAttribute(jso, "field3", "def3");
            			r.setAttribute("args", jso);
            //				vm.editRecord(r);
            //				vm.rememberValues();
            			
            			vm.editNewRecord(JSOHelper.convertToMap(r.getJsObj()));
            			vm.rememberValues();
            			
            		}
            	});
            	
            	IButton reset = new IButton("Reset values");
            	reset.addClickHandler(new ClickHandler() {
            		
            		public void onClick(ClickEvent event) {
            			vm.resetValues();
            		}
            	});
            	
            	HLayout layout = new HLayout();
            	layout.setWidth100();
            	layout.setHeight(600);
            	layout.setMembers(f1, f2, setDefs, reset);
            	layout.draw();
            }

            SmartClient Version: SC_SNAPSHOT-2012-01-25_v8.3d/Pro Deployment (built 2012-01-25)


            Am I defining the new record values wrongly?


            thanks,

            Comment


              #7
              Looks like there's a bug in 'resetValues()'
              Please try the next nightly build (Jan 31 or greater) and let us know if you still have problems with this

              Thanks
              Isomorphic Software

              Comment


                #8
                Ok, that case seems to be working.

                I'm playing around with the rememberValues(), resetValues() and clearValues().

                Create a form, fill something in.
                Press rememberValues()
                Change the fields
                Press resetValues()
                <= sets the values to the remembered values (OK)

                Press clearValues() to wipe out all fields.
                Press resetValues()
                <= does nothing. I expected a bit to get the first remembered values here.

                Seems that clearValues then remembers the empty values.
                Is that the intention?


                * underlying behaviour: one of the forms (so just a certain set of the fields in the valuesManager) can be disabled with a checkbox. When that happens, the values of that form should be cleared. When the form is enabled again, it should revert to its initial or previous values.


                thanks

                Comment


                  #9
                  It is indeed the case that we "remember" the cleared values.

                  The envisioned usage was that essentially you're editing an entirely new set of data when you "clearValues()" so if the user then makes some changes, which are then discarded, we should go back to the empty state.
                  This happens to be the opposite of what you expected for your use-case of course, but does make sense in other cases!

                  Probably easiest to just workaround this in your application -- call 'getValues()' or similar when you disable the form / clear the values, then call 'setValues()' or 'editRecord()' when you re-enable it.

                  Comment

                  Working...
                  X