Announcement

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

    disable editing of formItem

    Hi,

    We have a dynamic form in which we'd like, under certain circumanstances (e.g., user is in "Read-Only" mode), to disable editing of all the formitems. We tried a number of obvious solutions but they didn't work. Any assistnace is much appreciated. It seems like this should be relatively easy to do...

    Attempt #1:
    ==============

    We tried to set all FormItems to "StaticTextItem". This did prevent editing, but it had problems: boolean fields were changed from a checkbox look to a field with a string value of "true" or "false"; worse, combobox item's value ID values were shown instead of the actual display text. (That is, if the field's ds read like this:

    <field name="optionEX" title="Sample enzyme" type="text"
    length="255" section="General" simple="true" required="true">
    <valueMap>
    <value ID="-eT">Trypsin</value>
    <value ID="-eS">StrictTrypsin</value>
    <value ID="-eC">Chymotrypsin</value>
    <value ID="-eR">RalphTrypsin</value>
    <value ID="-eA">AspN</value>
    <value ID="-eG">GluC</value>
    <value ID="-eB">GluC Bicarb</value>
    <value ID="-eM">CNBr</value>
    <value ID="-eD">Trypsin/CNBr</value>
    <value ID="-e3">Chymotrypsin/AspN/Trypsin</value>
    <value ID="-eE">Elastase</value>
    <value ID="-eK">LysC / Trypsin_K (cuts after K not before P)
    </value>
    <value ID="-eL">LysN (cuts before K)</value>
    <value ID="-eP">LysN Promisc (cuts before KASR)</value>
    <value ID="-eN">Nonspecific or None</value>
    </valueMap>
    </field>

    then, when we set the fields to be StaticTextItem, it showed the id value of say "-eT" instead of the value "Trypsin".

    Attempt #2:
    ===============

    We tried to disable the formitem using this command:

    currentFormItem.disable();

    However, this greyed out the formitem label, removed the formitem icon (and also made it unclicable), and (as I recall) also made the actual formitem value values unclickable.

    Attempt #3:
    ==================

    We then tried to set the field's canEdit property to false as follows:

    currentFormItem.setAttribute("canEdit", "false") ;

    We also tried:

    currentFormItem.setAttribute("canEdit", false) ;

    But this did not seem to have any effect.


    So our question is: what's the best way to prevent a user from making any changes to a formitem, yet still preserver all other features (e.g., the label should appear in its normal color; the formitem icon should appear and still be clicable; for those formitems that have drop-downs, the formitems values should appear, and not the value ID; and ideally, the user can still click on the form item's drop down box to see the other options, but will NOT be allowed to make any changes. Finally, as a bonus, it'd be nice if the color background of the formitem were to change, (eg become grey) to indicate that the field is no longer editable.)

    (FYI: Although I don't think it's relevant, we're "constructing" our dynamic form by creating CheckboxItems, TextItems, FloatItems etc. and then adding it to the dynamic form by calling setFiedlds.)

    Additional infracstructure details are below:
    ==================================================

    OS: Windows XP Pro
    IDE: MyEclipse 9.0 with Google Plugin for Eclipse (2.3.1)
    SmartGWT EE 2.4
    Browwer: Mozilla Firefox 4.0.1
    GWT SDK: 2.2
    Sun JDK 1.6.0_13

    #2
    setCanEdit(false) before you create the form (although this now works as an on-the-fly setting too in SGWT 3.0).

    Comment


      #3
      Had the issue/requirement. Silly as it may sound we just hid the "Submit" button and left the "Cancel" button in place.

      Users got the point pretty quickly. As I said 'silly' solution but it worked better than converting all of form items to static text items.

      Comment


        #4
        We searched for "setCanEdit" in the javadoc for smartgwt (available on the web), but I did not see that method for any formitem, dynamicform, or for specific formitems such as "textitem"/"checkboxitem" etc. The only class that seems to support the "setCanEdit" method are listgridfields, as described here:

        http://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/widgets/grid/ListGridField.html#setCanEdit(java.lang.Boolean

        But we're dealing with dynamic forms. Is this "setCanEdit" a method that's only available for dynamicforms and/or formitems in SmartGWT 3.0, not SmartGWT 2.4?

        Comment


          #5
          Changing editability on the fly (setCanEdit) is part of 3.0. Use setAttribute() for now, but as previously indicated, this must be done before you create the form (or really, call setFields).

          Comment


            #6
            Are you sure it works dynamically with smgwt 3.0? I am using smartgwtpro 3.0p. I have to change the canEdit state of the form in the callback after filtering data because the canEdit state depends on the data (see code). But nothing happens, the form remains editable even if data sech that id==1 are selected? It works well if I change to setDisable(true) but I would prefer using setCanEdit(false) which allows to copy data.

            Code:
                    Criteria c1 = new Criteria();
                    c1.addCriteria("id",orderId);
                    vmOrders.filterData(c1, new DSCallback(){
            
            			@Override
            			public void execute(DSResponse response,Object rawData,DSRequest request) {
            				Record records[] = response.getData();
            				if (records.length==1){
            					int id  = records[0].getAttributeAsInt("id_person_owner");
            					formOrderInfo.setCanEdit(id==1);
            
            				}
            			}
                    	
                    });

            Comment


              #7
              I'm seeing the same thing in SmartClient Version: v8.2p_2012-05-09/PowerEdition Deployment (built 2012-05-09)

              setCanEdit(false) has no effect if the form has already been created.

              But even if this did work I'm not sure it will result in the effect we're looking for. When the field is not editable we would like it to look like a StaticTextItem, not grayed out like a disabled field. The only way I've found to do that is to include two fields on the form, the actual field and another one that is a StaticTextItem. The StaticTextItem has a valueFormatter to get the value from the real field. At runtime, instead of setCanEdit(false) or disable(), the real field is hidden and the StaticTextItem is shown.

              This is a lot of work to go through for something that seems like a very common need. Is there an alternative?

              Comment


                #8
                The effect of setCanEdit() is, as you say, to switch to a StaticTextItem style of rendering rather than to make the item disabled.

                Which API isn't working for you - DynamicForm.setCanEdit or FormItem.setCanEdit?

                If it's FormItem.setCanEdit, are you possibly calling it on a FormItem you passed to setEditorType()? That won't work, you'll need to get the live item via getItem().

                Comment


                  #9
                  I'm calling form.getItem("myItem").setCanEdit(false). Not doing anything with setEditorType(). Do I need to markForRedraw() or should that just happen.

                  Comment


                    #10
                    It finally dawned on me that what we really want is for the FormItem to be disabled but for it to "look better". When the label and displayed value are grayed out it makes the form hard to read. Other than that the disabled behavior is exactly what we want. I put this into our custom css file and I think it gets us pretty much what we want.

                    .textItemDisabled,
                    .formTitleDisabled,
                    .selectItemTextDisabled {
                    color:black;
                    }

                    Comment


                      #11
                      Originally posted by jay.l.fisher View Post
                      It finally dawned on me that what we really want is for the FormItem to be disabled but for it to "look better". When the label and displayed value are grayed out it makes the form hard to read. Other than that the disabled behavior is exactly what we want. I put this into our custom css file and I think it gets us pretty much what we want.

                      .textItemDisabled,
                      .formTitleDisabled,
                      .selectItemTextDisabled {
                      color:black;
                      }
                      It looks really like editable. that did the trick. thanks!

                      Comment

                      Working...
                      X