Announcement

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

    How can use Section in DyamicForm if I am rendering fields using DataSource.

    I want to use Section in my DynamicForm but I am rendering fields using DataSource. Do I need to define Section in DataSource itself?

    Thanks.

    #2
    Defining Section in DataSource worked for me but I need to give name attribute in addition to make it work as below:

    { name:"ri",
    defaultValue: "Required Information",
    type: "section",
    sectionExpanded: false,
    itemIds: [
    "id","name"
    ]}

    If I dont give name, subsequent Section will not appear.
    Please let me know if there can be any limitations by doing this?


    Thanks.

    Comment


      #3
      See the docs for DataBoundComponent.fields. You can define fields on a component in addition to in the DataSource, and the are combined in a way that allows per-component customization.

      Comment


        #4
        Actually, I am using generic class which creates DynamicForm for me for any DataSource I provide at runtime. So, DS is only thing where I am doing specific things and rest of the code is generic so that I don't need to write same thing again for every form.

        The approach I am following is working but only thing is that if section is closed (collapsed) then validations are not working and forms gets closed without saving anything.

        Is this the side effect of the approach I am following.

        Comment


          #5
          Not sure, you haven't really shown enough code to tell. Try creating the simplest possible version of the problem.

          Comment


            #6
            Below is the code to create a generic DynamicForm which is defined in a custom class:

            this.form = isc.DynamicForm.create({
            dataSource:"",
            useAllDataSourceFields:true,
            showInlineErrors: true,
            width:"100%",
            height:"100%",
            autoDraw:false,
            //showTitlesWithErrorMessages :false,
            numCols: 4,
            colWidths: ["25%", "25%"],
            requiredTitleSuffix :"* :",
            titleOrientation: "left",

            fields: [
            ]
            });


            This way I can use the same code for every form I create and I just need to set the datasource accordingly.

            So, now I wanted to have sections in my form so I declared a type=section field in datasource itself and its showing sections as expected but if the sections are collapsed then validations don't work and saveData is called which is causing errors at server side in turn.

            below is the section declaration.
            {
            name:"bi",
            defaultValue: "Basic Information",
            type: "section",
            showIf :"this.form != null",
            sectionExpanded: false,
            itemIds: [
            "code","name"
            ]
            },


            I want that if the sections are closed then also I should be able to validate fields in that collapsed section and if there are errors then section should expand to show inline field errors.

            Please let me know if my requirement is not valid or I need to give some more code or explanation about requirement.

            Thanks a lot.

            Comment


              #7
              DataBoundComponent Complex Field - Example

              Hello,

              I have exactly the scenario as described in your documentation below - and I was wondering if there was an example list/form that you can point me to that show this in action? I have looked around but do luck. Thanks!

              -------

              showComplexFields [IRW] [Advanced] type:Boolean, defaultValue: true

              Whether to show fields of non-atomic types when a DataBoundComponent is given a DataSource but no component.fields.

              If true, the component will show fields that declare a complex type, for example, a field 'shippingAddress' that declares type 'Address', where 'Address' is the ID of a DataSource that declares the fields of a shipping address (city, street name, etc).

              Such fields may need custom formatters or editors in order to create a usable interface, for example, an Address field in a ListGrid might use a custom formatter to combine the relevant fields of an address into one column, and might use a pop-up dialog for editing.
              --------

              Comment


                #8
                Try simply setting that attribute to true using any nested DataSources, for example, the ones in the Master-Detail Batch Load & Save example.

                Comment


                  #9
                  Originally posted by Isomorphic
                  Try simply setting that attribute to true using any nested DataSources, for example, the ones in the Master-Detail Batch Load & Save example.
                  Thanks for that quick response. A small addition to the question - If I want to display the complex type in different sections in a Dynamic form, what's best way to do it? I am trying to use the following within the DataSource.ds.xml file, which creates the section, but I can't collapse it. My general question is, where is the master reference for all the possible <field> attributes? I couldn't find a description for type="Section" anywhere, except in this thread.

                  Thanks,

                  _K

                  Comment


                    #10
                    You specify a SectionItem by setting editorType:"SectionItem" - see the docs for this property.

                    Non-data fields like a section should not appear in the DataSource definition (this: what would a ListGrid do with it?). So you want a separate form definition that specifies sections. See the docs for useAllDataSourceFields in order to minimize duplication.

                    Comment


                      #11
                      Originally posted by Isomorphic
                      You specify a SectionItem by setting editorType:"SectionItem" - see the docs for this property.

                      Non-data fields like a section should not appear in the DataSource definition (this: what would a ListGrid do with it?). So you want a separate form definition that specifies sections. See the docs for useAllDataSourceFields in order to minimize duplication.
                      Thanks. Agreed with your MVC separation point. Though, the option of setting the editorType in the DataSource falls in the same breach, in my opinion. In any case, I added this to my DataSource to test it. I do see section headers with title "Section Header" with a "-" as prefix, implying that the sections are expanded. But I don't see any of the fields I'd expect to see under it. Meerly section headers that don't seem to do anything. Here's my Datasource -

                      <DataSource
                      ID="Account"
                      serverConstructor="com.xxx"
                      beanClassName="com.xxx.Account"
                      >
                      <fields>
                      <field type="sequence" name="jdoID" hidden="true"/>
                      <field type="text" name="number" title="Number" required="true"/>
                      <field type="text" name="name" title="Name" required="true"/>
                      <field type="text" name="webSite" title="Website">
                      <field type="text" name="description" title="Description" length="2000"/>


                      <field name="Billing" title= "Billing Address" multiple="false"
                      type="Address" showComplexFields="true" editorType="SectionItem"
                      javaClass="com.xxxAddress"
                      />

                      <field name="Shipping" title= "Shipping Address" multiple="false"
                      type="Address" showComplexFields="true" editorType="SectionItem"
                      javaClass="com.xxx.Address"
                      />

                      <field name="Phone" title= "Phone Number" multiple="false"
                      type="PhoneNumber" showComplexFields="true" editorType="SectionItem"
                      javaClass="com.xxx.PhoneNumber"
                      />

                      <field name="Fax" title= "Fax Number" multiple="false"
                      type="PhoneNumber" showComplexFields="true" editorType="SectionItem"
                      javaClass="com.xxx.PhoneNumber"
                      />
                      </fields>

                      </DataSource>


                      Also, I am not clear as to what you mean by - you want a separate form definition that specifies sections - Are you suggesting to add the fields in the form one by one and explicitly putting them in sections? If so, that defeats what I am trying to achieve.

                      Thanks for all your help.

                      _K

                      Comment


                        #12
                        Presentation hints make sense in the DataSource when they are generic and do not apply only to a particular type of DataBoundComponent (eg SectionItem is specific to DynamicForm).

                        See SectionItem.itemIds, then see this discussion of DataBoundComponent.fields from the SmartClient docs - same concepts apply, we'll find a way to surface this doc within SmartGWT.

                        Comment


                          #13
                          Originally posted by Isomorphic
                          Presentation hints make sense in the DataSource when they are generic and do not apply only to a particular type of DataBoundComponent (eg SectionItem is specific to DynamicForm).

                          See SectionItem.itemIds, then see this discussion of DataBoundComponent.fields from the SmartClient docs - same concepts apply, we'll find a way to surface this doc within SmartGWT.
                          Thanks for your quick response. Appreciate it. I have read all the areas you have hilighted in your responses and tried to incorporate as much as possible - but it seems like (since the editorType="SectionItem" doesn't work and I still don't see a way to create a generic form) I am left with custom coding the view by manually creating the sections as needed.

                          Cheers,

                          _K

                          Comment


                            #14
                            ??? those docs point out multiple ways to achieve what you want. Take another read. Follow the link to useAllDataSourceFields this time.

                            Comment


                              #15
                              Originally posted by Isomorphic
                              ??? those docs point out multiple ways to achieve what you want. Take another read. Follow the link to useAllDataSourceFields this time.

                              Unfortunately I don't see a way following the documentation. Unless you can show me to a specific code sample that does what I am trying to do, I am affraid but I am at a loss.

                              _K

                              Comment

                              Working...
                              X