Announcement

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

    How to set default value for field

    Is there any way to specify the default value for a field in the ds.xml so that when a new record is initialized for a DynamicForm or ListGrid row the initial value for the field will be set? In this particular case it is a date field.

    #2
    Yes, use <value fieldName="fieldName" value="value"/> in an operationBinding. The value can be a Velocity expression.

    Comment


      #3
      Nice to know about that, but I don't think it is what I'm looking for. In this case I want the default value to appear in a DynamicForm when a new record is being edited. I'm using a reusable component for the editor UI so I want to keep the default value in the ds.xml rather than having the "generic" editor include code for specific datasource fields.

      Comment


        #4
        Then have your editor look for a special property (named whatever you like) on your DataSourceField.

        Comment


          #5
          Ah, of course. I'm still getting used to the idea that you can hang whatever you like on a datasource. Very powerful feature. Thanks.

          Comment


            #6
            Did I stumble across an undocumented feature? All I've done so far is add defaultValue="Something" to my field in the ds.xml and the DynamicForm shows that value when a new DynamicForm is created.

            Is there any way to make the defaultValue the current date?
            Last edited by jay.l.fisher; 27 May 2010, 07:13.

            Comment


              #7
              DataSourceField properties are inherited by DataBoundComponent fields. It's kind of a hack to use a component-specific property in the DataSource as it may have unintended effects on other components. Better to use a custom property of your own devising.

              Comment


                #8
                Originally posted by Isomorphic
                Yes, use <value fieldName="fieldName" value="value"/> in an operationBinding.
                This confuses me.
                If I create such a DataSource with a value in an operationBinding of type "add", and call form.editNewRecord() on the form, will those default values show up on the fields in the form?
                I thought operationBindings aren't hit until you actually call them via e.g. form.saveData() in which case these values would only be seen by a user after the actual add to the backend.
                Is that correct?

                Comment


                  #9
                  Yes that's exactly right - the initial suggestion - using a <value...> tag in an operation binding - would provide a default value when a value was saved to the server only -- it wouldn't show up in the editor as a defaultValue.

                  As suggested above - if you want a custom value to show up as a default in your editor you can apply some arbitrary attribute to your dataSourceField and have your editor pick up this value in your client side code.

                  Comment

                  Working...
                  X