Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

REST length validator

$
0
0
Hello.

DataSource definition
Code:

<DataSource ID="myDS" serverType="sql" tableName="myTable">
  <fields>
      <field name="myField" type="text" length="3"/>
  </fields>
</DataSource>

REST POST request
Code:

{
    dataSource:"myDS",
    operationType:"add",
    data:{
      myField: "abcd"
    }
}

In myTable I have a single column defined to take maximum 3 characters.
All works well in the UI, because the FormItem I create related to the datasource field myField will accept only 3 characters at maximum.
The problem is that if I send a REST request targeting that datasource, I will end up with an ugly DB exception, since I cannot store in the column more than 3 characters.
To make sure this does not happen I need to change my field definition in the DS to

Code:

<DataSource ID="myDS" serverType="sql" tableName="myTable">
  <fields>
      <field name="myField" type="text" length="3">
              <validators>
                  <validator type="lengthRange" max="3"/>
              </validators>
      </field>
  </fields>
</DataSource>

The question is, couldn't smartgwt have such implicit validator when defining the length of the field?

Viewing all articles
Browse latest Browse all 4756

Trending Articles