Announcement

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

    DataSourceField.canEdit doesn't work with custom types

    Hi,

    SmartClient Version: SC_SNAPSHOT-2011-01-25/EVAL Deployment

    I have added a standalone testcase, the DataSourceField.setCanEdit(false) doesn't seem to work with custom types?

    Originally posted by documentation

    DataSourceField.canEdit [IR] type:Boolean, defaultValue: null

    Whether this field can ever be edited by the user. If set to false, no DataBound component will ever try to offer an editing interface for this field.
    Regards,
    Bart

    Code:
    public class Standalone implements EntryPoint {
    	
    	/**
    	 * Container for either the login window or the workspace;
    	 */
    	private static Canvas masterPanel = null;	
    
    	 public void onModuleLoad() {  
    	 		
    		masterPanel = new Canvas(); 
    		masterPanel.setHeight100();
    		masterPanel.setWidth100();
    		masterPanel.setStyleName("pageBackground"); //background style from skin
    			  
    		    DataSource dataSource = new DataSource();   
    		    
                         //Plain old TextItem
    	        DataSourceField myTextField1 = new DataSourceField();   
    	        myTextField1.setName("textField1");   
    	        myTextField1.setTitle("textField1");   
    	        myTextField1.setCanEdit(false);
    		    
                         //Custom TextItem
    	        DataSourceField myTextField2 = new DataSourceField();   
    	        myTextField2.setName("textField2");   
    	        myTextField2.setTitle("textField2");   
    	        myTextField2.setType(new MyTextType());   
    	        myTextField2.setEditorType(new MyTextEditor());
    	        myTextField2.setCanEdit(false);
    	  
    	        dataSource.setFields(myTextField1, myTextField2);  
    
    		    //the order list grid   
    		    DynamicForm form = new DynamicForm();   
    		    form.setHeight(170);   
    		    form.setWidth(500);
    		    form.setDataSource(dataSource);    
    		
    			masterPanel.addChild(form);
    			masterPanel.draw();	
    		}
    	    
        public static class MyTextType extends SimpleType {   
            public MyTextType() {   
                super("myTextType", FieldType.ANY);   
     
            }   
        }  
        
        private class MyTextEditor extends TextItem {
    
        	private String text;
    
        	public MyTextEditor() {
        		super();
        		
        	}
        }
    
    }
    Attached Files

    #2
    canEdit:false works by selecting a StaticTextItem as the FormItem when a DynamicForm binds to the DataSource - in this case you're specifying a particular EditorType so this is always used.

    We will be adding an API SimpleType.setReadOnlyEditorType() so you can avoid this side-effect when specifying a custom editor. However, in the meantime, we would recommend having your custom editor check for the canEdit attribute and reject all changes, and perhaps style itself differently.

    Comment


      #3
      An update on this: We have now added support for 'setReadOnlyEditorType()' at the DataSourceField or SimpleType level.
      The pattern is the same as for setEditorType() - the method takes a form item instance and uses it as a configurator for the item when the field is in 'canEdit:false' mode.
      As a concrete example, you could get the code in this thread working by calling 'myTextField2.setReadOnlyEditorType(new StaticTextItem());'

      This will show up in the next nightly build

      Comment


        #4
        Sounds good. But there is no default for this, is there?

        Comment


          #5
          Correct, there is no default.

          Comment


            #6
            Hi,

            Just implemented this new functionality and everything works great!
            Is it possible to add the "getReadOnlyEditorType()" operation as well?

            Regards,
            Bart

            Comment


              #7
              Hi,

              Originally posted by Isomorphic
              An update on this: We have now added support for 'setReadOnlyEditorType()' at the DataSourceField or SimpleType level.
              The pattern is the same as for setEditorType() - the method takes a form item instance and uses it as a configurator for the item when the field is in 'canEdit:false' mode.
              Is it possible to change this canEdit property on the fly on a drawn form?
              I.e. depending on some value from a field, another field should become canEdit: false and should show its ReadOnlyEditorType.

              Trying it manually, but a even markForRedraw doesn't seem to have effect.

              Comment


                #8
                No, you can't change it on the fly since the FormItem type to use has already been chosen. As mention above, if you need to switch from readOnly to editable on the fly, we would recommend having your custom editor check for the canEdit attribute and reject all changes, and perhaps style itself differently.

                Comment

                Working...
                X