Announcement

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

    AutoFitTextAreaItem still editable after form.setCanEdit(false);

    Unlike other form item types, the AutoFitTextAreaItem doesn't inherit the message from the containing form for the setCanEdit() method.
    That is, if I configure the text area with "setCanEdit(false)", calling form.setCanEdit(true) does not make the text area editable. Similarly, form.setCanEdit(false) does not disable editing of the text area.

    I'm trying to make the form edit/save/cancel functionality somewhat generic. This problem lets unexpected concerns leak into the code.
    Form item initialization:
    Code:
    		final AutoFitTextAreaItem textInput = new AutoFitTextAreaItem("text");
    		textInput.setShowTitle(false);
    		textInput.setWidth("*");
    		textInput.setColSpan(4);
    		textInput.setCanEdit(false);
    Event handler for "Edit" toolstrip button:
    Code:
    	public void startEditing() {
    		this.form.setCanEdit(true);
    		// handle TextAreaItem members
    		// currently done by item name
    		final FormItem textItem = form.getItem("text");
    		if (textItem != null) {
    			textItem.setCanEdit(true);
    		}
    		this.saveButton.show();
    		this.cancelButton.show();
    		this.resetButton.show();
    		if (this.extraEditButtons != null) {
    			for (final ToolStripButton button : extraEditButtons) {
    				button.show();
    			}
    		}
    		this.modifyButton.hide();
    	}
    1. Isomorphic SmartClient/SmartGWT Framework (SNAPSHOT_v8.3d_2012-10-09/Enterprise Deployment 2012-10-09)

    2. browser(s) and version(s) involved: IE 9

    3. N/A

    4. N/A

    5. N/A

    6. Please let me know if the code above needs more detail.

    #2
    This sounds like it may be a case of your expectations not matching the design.

    The intended behavior is as follows:
    - by default canEdit is unset at the item (field) level
    - if explicitly set to true or false at the item level, this will be respected
    - otherwise, if the form as a whole has canEdit explicitly set to true or false, that will be respected at the item level too.

    This sounds like what you're describing with autoFitTextAreaItems (implying they're perhaps behaving correctly by respecting the property set at the item level, if specified).
    However you're also saying this is inconsistent across item types. Could you show us your code that leads you to this conculsion?

    Thanks
    Isomorphic Software

    Comment


      #3
      Here is the method I'm using to create select items:
      Code:
      	/**
      	 * Create a SelectItem using the property provided. If the property allows
      	 * multiples, then the correct behavior will be defined. Internally, this
      	 * uses the propertyName to assign the correct option
      	 * DataSource.
      	 * 
      	 * @param propertyName
      	 *            This is also the ID of the field for use in the page.
      	 * @param multiple
      	 * @return SelectItem configured for property
      	 */
      	private SelectItem createSelectItemForProperty(String propertyName,
      			boolean multiple) {
      		final SelectItem selectItem = new SelectItem(propertyName);
      		final String dataSourceName = (multiple && propertyName.endsWith("s")) ? propertyName
      				.substring(0, propertyName.length() - 2) : propertyName;
      		selectItem.setOptionDataSource(DataSource.get(dataSourceName));
      		selectItem.setDisplayField("description");
      		selectItem.setMultiple(multiple);
      		selectItem.setSortField("description");
      		return selectItem;
      	}
      I don't call "setCanEdit(...)" explicitly on these. They correctly inherit the editable property of the form.

      If I comment out the "setCanEdit(...)" call on the text area item, it is always editable.

      Comment


        #4
        In our testing calling 'setCanEdit()' at the form level successfully sets whether or not items are editable at the item level without the need to also call setCanEdit() on the items themselves.

        Here's a test case demonstrating this:
        Code:
        import com.google.gwt.core.client.EntryPoint;
        import com.smartgwt.client.widgets.Button;
        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.AutoFitTextAreaItem;
        import com.smartgwt.client.widgets.form.fields.SelectItem;
        
        public class InheritingCanEdit implements EntryPoint {
        
            @Override
            public void onModuleLoad() {
                
                
                SelectItem selectItem = new SelectItem("select");
                selectItem.setValueMap("V1", "V2", "V3");
                
                AutoFitTextAreaItem textInput = new AutoFitTextAreaItem("text");
                textInput.setShowTitle(false);
                textInput.setWidth("*");
                textInput.setColSpan(4);
                
                final DynamicForm form1 = new DynamicForm();
                
                form1.setBorder("1px solid red");
                form1.setItems(selectItem, textInput);
                
                form1.draw();
                
                // canEdit:false form
                
                SelectItem selectItem2 = new SelectItem("select");
                selectItem2.setValueMap("V1", "V2", "V3");
                
                AutoFitTextAreaItem textInput2 = new AutoFitTextAreaItem("text");
                textInput2.setShowTitle(false);
                textInput2.setWidth("*");
                textInput2.setColSpan(4);
                
                final DynamicForm form2 = new DynamicForm();
                
                form2.setBorder("1px solid green");
                form2.setLeft(200);
                form2.setItems(selectItem2, textInput2);
                // initially false
                form2.setCanEdit(false);
                form2.draw();
                
                // Enable / disable canEdit at runtime:
                canEdit = true;
                final Button toggleCanEdit = new Button("Set CanEdit False");
                toggleCanEdit.addClickHandler(new ClickHandler() {
                    
                    @Override
                    public void onClick(ClickEvent event) {
                        if (canEdit) {
                            form1.setCanEdit(false);
                            form2.setCanEdit(false);
                            toggleCanEdit.setTitle("Set CanEdit True");
                        } else {
                            form1.setCanEdit(true);
                            form2.setCanEdit(true);
                            toggleCanEdit.setTitle("Set CanEdit False");
                            
                        }
                        canEdit = !canEdit;
                        
                    }
                });
                toggleCanEdit.setTop(200);
                toggleCanEdit.draw();
            }
            private boolean canEdit;
        
        }
        If you think you've found a case where this isn't working correctly please show us a runnable test case and we'll take a look

        Thanks
        Isomorphic Software

        Comment


          #5
          I'll see if I can quickly put together a small test case just within an onModuleLoad() as you've done.

          Offhand, though, I see two differences. First, the sample form you've coded isn't bound to a datasource. Second, in my code I'm calling "edit()" before "setCanEdit()":
          Code:
          		this.form.editRecord(editedRecord);
          		this.form.setCanEdit(false);
          I'll continue to review your sample to see if I'm coding something incorrectly. Thanks.

          Comment


            #6
            Taking your sample and adding in a datasource + editRecord() call, I am unable to reproduce the incorrect behavior I'm seeing elsewhere. I will analyze the code to find the difference(s).
            Thanks for your help.

            Comment

            Working...
            X