Announcement

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

    How to pre populate a text field with a value from a column in sql table

    I am using isomorphic smartClient v10.0. I have a situation in my current project where I need to pre populate a text field in a dynamic form with a value equal to the maximum value of a column in a sql table. Is there any way I can achieve it? I have created a function in a java class which will return that maximum value from a sql column. But, how to store it in an isomorphic dynamic form field?

    I will appreciate any help in this matter.

    Regards,
    Akash

    #2
    Hi,

    get the value via a DataSource-call with a special operationBinding, then build the GUI in the callback and set the default value accordingly.

    Best regards
    Blama

    Comment


      #3
      FYI: With server summaries you can do this in your .ds.xml (Power version and above) and don't need any Java code.

      Comment


        #4
        What I did is:

        {name: "code", type: "text",canEdit: true, required: true, length: 170, width: "*", allowEmptyValue: false,
        optionDataSource: isc.DataSource.create({
        dataFormat: "json",
        clientOnly: true,
        showPrompt: false,
        dataURL: "constituent/constCode",
        fields: [{name: "id", type: "text"}],
        handleError: function(response, request) {isc.warn("Error reading constituent codes.");return false;}
        }
        )

        This 'constituent/constCode' dataURL points to a function which returns a string value. Is this process correct?

        Comment


          #5
          Hi,

          I'm not sure why you try to simulate something clientOnly in JavaScript. Why don't you use a real DataSource? You were saying the value should come from a SQL table (=the server).

          Best regards
          Blama

          Comment


            #6
            Thats what my project demands. can I link the data source to a method or function() which will execute a sql query and return me a string value ?

            Comment


              #7
              If I want to create a data source which can be linked to a method(which in turns returns a string value), then can I do it? If yes, how?

              Comment


                #8
                Quite simple to do, but you should start by reading the QuickStart Guide, Server Framework chapter, to get an idea of the basics which you don't appear to be aware of.

                Comment


                  #9
                  Thank you sir! But, I will appreciate if you can say why every time I try to fetch data through DataURL, it shows the field as a 'Select' drop down menu even though I have set the field as 'Text'

                  Comment


                    #10
                    You're specifying type:"text" - this tells the system the data type, not the UI control to use. Then, based on the fact that you have an optionDataSource, it chooses a SelectItem as the appropriate UI control. If you want to override this, you would specify editorType:"TextItem".

                    Comment


                      #11
                      Thanks!

                      Comment


                        #12
                        Hello,

                        I did your way and it worked. I just have a simple query over this. If at all, I wont use optionDataSource, instead I use only dataSource and try to fetch the data and populate on a textfield without any dropdown, then will the below code work?

                        {name: "code",type: "text", canEdit: true, required: true, length: 170, width: 180,
                        dataSource: isc.DataSource.create({
                        dataFormat: "json",
                        clientOnly: true,
                        // editorType:"TextItem",
                        allowEmptyValue: false,
                        showPrompt: false,
                        dataURL: "constituent/constCode",
                        fields: [{name: "code", type: "text"},{name: "id", type: "text"}],
                        handleError: function(response, request) {isc.warn("Error reading constituent codes.");return false;}
                        }
                        )

                        Will appreciate your views in it. Thanks a lot!

                        Comment


                          #13
                          Click image for larger version

Name:	Code.jpg
Views:	182
Size:	13.7 KB
ID:	248209 It is coming something like the above attachment. I want the textField to similar to description but populating that value with no additional titles like 'Code' or two boxes.

                          Comment


                            #14
                            There is no such documented property formItem.dataSource, and generally if you just make up new properties, that won't work.

                            Go back to using optionDataSource and simply read the docs for it - it exists to allow a query from a related table, saving an ID value while showing the end user some other user-friendly property or properties. There are also many samples to look through.

                            Comment


                              #15
                              Can you send me a link to such sample? I did the below code by reading the values from related table.
                              {name: "code",type: "text", canEdit: true, required: true, length: 170, width: 180, allowEmptyValue: false, editortype: "TextItem",
                              optionDataSource: isc.DataSource.create({
                              dataFormat: "json",
                              clientOnly: true,
                              allowEmptyValue: false,
                              showPrompt: false,
                              dataURL: "constituent/constCode",
                              fields: [{name: "code", type: "text"}],
                              handleError: function(response, request) {isc.warn("Error reading constituent codes.");return false;}
                              }
                              )


                              It still displays like the below: I want this @WASH0115310 to come in the text box field not in drop down. Moreover, it retrieves correct data. The only problem it does not display in the text Box. Click image for larger version

Name:	Code.jpg
Views:	181
Size:	7.8 KB
ID:	248223

                              Comment

                              Working...
                              X