Announcement

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

    How to add FormItem to an existing DynamicForm

    DynamicForm does not have an addField(FormItem field) method.
    This is inconsistent with DataSource.addField(DataSourceField field).

    I would like to propose adding an addFieldmethod to DynamicForm.

    As a workaround I tried the following code:

    Code:
            DynamicForm form = ...
            CanvasItem newItem = ...
            FormItem[] fields = form.getFields();
            FormItem[] newFields = new FormItem[fields.length+1];
            System.arraycopy(fields, 0, newFields, 0, fields.length);
            newFields[fields.length] =newItem;
            form.setFields(newFields);
    This code gives the following stack trace:

    Code:
    [ERROR] Unable to load module entry point class com.acme.Application (see associated exception for details)
    com.google.gwt.core.client.JavaScriptException: (TypeError): this.form has no properties
     fileName: http://localhost:8888/com.acme.Application/sc/modules/ISC_Forms.js
     lineNumber: 1173
     stack: ()@http://localhost:8888/com.acme.Application/sc/modules/ISC_Forms.js:1173
    ()@http://localhost:8888/com.acme.Application/sc/modules/ISC_Forms.js:1411
    ([object Object],undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined)@http://localhost:8888/com.acme.Application/sc/modules/ISC_Forms.js:1408
    ([object Object])@http://localhost:8888/com.acme.Application/sc/modules/ISC_Core.js:302
    ([object Object],"CanvasItem")@http://localhost:8888/com.acme.Application/sc/modules/ISC_Forms.js:238
    ([object Array],null,true,undefined)@http://localhost:8888/com.acme.Application/sc/modules/ISC_Forms.js:227
    ([object Array])@http://localhost:8888/com.acme.Application/sc/modules/ISC_Forms.js:216
    ([object Array])@http://localhost:8888/com.acme.Application/sc/modules/ISC_Forms.js:217
    ([object Object])@http://localhost:8888/com.acme.Application/sc/modules/ISC_Core.js:324
    ("fields",[object Array])@http://localhost:8888/com.acme.Application/sc/modules/ISC_Core.js:322
    ("fields",[object Array])@jar:file:/home/najmi/.m2/repository/com/smartgwt/smartgwt/1.0b3-SNAPSHOT/smartgwt-1.0b3-SNAPSHOT.jar!/com/smartgwt/client/widgets/BaseWidget.java:641
    gwtOnLoad([object Window],"com.acme.Application","1.5")@:0
    gwtOnLoad((function () {alert("Failed to load module com.acme.Application\".\nPlease see the log in the development shell for details.");}),"com.acme.Application","http://localhost:8888/com.acme.Application/")@http://localhost:8888/com.acme.Application/hosted.html?com_wellfleetsoftware_gis_gui_gwt_Application:20
    maybeStartModule()@http://localhost:8888/com.acme.Application/com.acme.Application.nocache.js:100
    ()@http://localhost:8888/com.acme.Application/com.acme.Application.nocache.js:354
    @http://localhost:8888/com.acme.Application/hosted.html?com_acme_Application:39
    
        at com.smartgwt.client.widgets.BaseWidget.setProperty(Native Method)
        at com.smartgwt.client.widgets.BaseWidget.setAttribute(BaseWidget.java:531)
        at com.smartgwt.client.widgets.form.DynamicForm.setFields(DynamicForm.java:1693)
    Any workarounds on how to do this? Thanks.

    #2
    You can't reuse the same items across different forms or different calls to setFields(), create fresh ones instead (the documentation now more explicitly points this out).

    Most of the time, the best way to do conditional fields is to create additional fields and use item.show()/hide() to affect which ones are showing.

    Comment


      #3
      Originally posted by Isomorphic

      Thanks for clarifying how things work.

      Most of the time, the best way to do conditional fields is to create additional fields and use item.show()/hide() to affect which ones are showing.
      My case is not one of conditional field but where a Form has fields being added to it at different levels of a class hierarchy. Yes I could create a separate Form at each level in class hierarchy and add them to same ValuesManager, but I need some visual cohesion and to make use of empty space in a multi-column form.

      I suspect this is a common enough need that it may make sense to add an addField method to DynamicForm. I can submit a patch for that to help out if there is support for suggestion. Thanks.

      Comment


        #4
        Subforms make sense for subobjects. Among many, many other issues, you could have field name collisions.

        addField() is trivial to implement, what's not trivial is working through the semantics of exactly what it should mean with respect to the form's current values, where the focus and cursor are, and the form's relationship to it's DataSource. Not a place where we're looking for a patch, but thanks for offering.

        Comment


          #5
          Hello,
          We are trying to hide fileitems and set it visible to permit multiple upload, but we get this error.
          We tried both with smartgwt 1.0b2 and 1.0b3SNAPSHOT from Apr. 4th

          here is the code :
          Code:
          uploadForm = new DynamicForm();
          uploadForm.setEncoding( Encoding.MULTIPART );
          UploadItem fileItem = new UploadItem( "Joindre un fichier" );
          fileItem.hide();
          and the error
          Code:
          [ERROR] Uncaught exception escaped
          com.google.gwt.core.client.JavaScriptException: (TypeError): self.hide is not a function
          ...
          ... 
          at com.smartgwt.client.widgets.form.fields.FormItem.hide(Native Method)
          Any sugestion ?
          Thanks

          Comment


            #6
            Try FormItem.setVisible(false)

            From the javadocs :

            Whether this item is currently visible. visible can only be set on creation. After creation, use show() and hide() to manipulate visibility.

            Comment


              #7
              it works
              Thanks!

              Comment

              Working...
              X