Limiting the text length of columns while adding or editing a row.

Limiting the text length of columns while adding or editing a row.

nandank99nandank99 Posts: 6Questions: 1Answers: 0
edited January 2014 in Editor
Hi all
I am facing an issue where i want to limit maximum text length a user can enter while creating or editing a row .
I am using Editor.Can this be done?
Please suggest .

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi,

    Yes absolutely this can be done. On the server-side use a validation method:

    [code]
    Field::inst( 'myField' )
    ->validator( 'Validate::maxLen', 100 )
    [/code]

    And on the client-side you can use the text input control's `maxlength` option which you pass through the text field type's `attr` object: https://editor.datatables.net/fields/#text (example of maxlength in the documentation.

    Allan
  • nandank99nandank99 Posts: 6Questions: 1Answers: 0
    Thanks Allan.
    I am able to achieve the client side validation now.But i think ended up doing in different manner:)
    In course ,I went through this tutorial -(https://editor.datatables.net/release/DataTables/extras/Editor/examples/clientValidation.html) and implemented this approach for client side validation-
    I suspect that you are talking about another approach for client side validation .i have still not got my heads around that.Please intervene if i am not following the correct method for doing the client side validation:-)
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Yes, the method shown in that example is perfectly valid as well! Lots of way to do it :-)

    Personally, I feel that rather than duplicating code, just let the server do the validation - unless you need it to be realtime of course... (keyup etc).

    Allan
This discussion has been closed.