Announcement

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

    How to conditionally set a ListGridField required on a row?

    Hi,

    We've been trying to achieve similar functionality on ListGrid that already exists for FormItems: com.smartgwt.client.widgets.form.validator.RequiredIfValidator;
    We want to set a ListGridField to required conditionally.
    Ie. we got ListGridFields A = "Need more coffee? If not, why?" and B for answering the question. B is not required until A has a certain value.

    We tried using the same validator for the ListGridField and got the validator to fire, but it does not change the field's required attribute, no matter what gets returned from the RequiredIfFunction's execute() method

    Is there a neat way to achieve what we're trying to do?

    We are using SmartGWT Pro, nightly build 20110630.

    #2
    Is that a no?

    Comment


      #3
      Surely someone has dealt with this problem. Please step up and tell me how it's done :)

      Comment


        #4
        Are we alone with this problem?

        Comment


          #5
          Hi Isomorphic,

          could you answer the above question? I'm having the same problem.
          Also I think the docs are unclear here (at least to me):

          .ds.xml docs:
          RequiredIf type validators should be specified with an expression property set to a stringMethod, which takes three parameters:
          • item - the DynamicForm item on which the error occurred (may be null)
          • validator - a pointer to the validator object //What is this?
          • value - the value of the field in question
          • record - the "record" object - the set of values being edited by the widget
          Also, when clicking stringMethod, the content seems to be SmartClient-related. Is it possible to use RequiredIf from .ds.xml in SmartGWT?


          Java-RequiredIfValidator docs:
          RequiredIf type validators should be specified with an expression which takes three parameters:
          • item - the DynamicForm item on which the error occurred (may be null)
          • validator - a pointer to the validator object
          • value - the value of the field in question
          Again the problem is with validator. The constructor parameter RequiredIfFunction only has formItem and value as parameters.

          A showcase sample (or BuiltInDS-testcase here in this thread) showing the usage here would really help.

          Thank you,
          Blama

          Comment


            #6
            As far as the original question, the user seems to expect that the field's "required" attribute will change - it won't. Like all other Validators, requiredIf will simply produce an error if the condition is not met.

            To use RequiredIf Validator in SmartGWT, you provide a RequiredIfFunction via setExpression(). We do see that one part of the docs mentions a "validator" parameter that isn't actually passed (and doesn't apply to SmartGWT), but this shouldn't be any barrier to using the API in the way it obviously functions - RequiredIfFunction has an "execute" method that you implement and return a boolean.

            To use RequiredIf from a .ds.xml file within SmartGWT, you'd need to write a JavaScript function (because the GWT compiler does not process .ds.xml files). We'd recommend against trying this unless you, for other reasons, want to pick up proficiency in SmartClient.

            Comment

            Working...
            X