Override field name for validation display

7 posts, 1 answers
  1. M
    M avatar
    29 posts
    Member since:
    Oct 2012

    Posted 28 Mar 2013 Link to this post

    Is there a way to alter the text that is displayed in validation messages, rather than using the field names from the model?

    For example, I have a datasource hooked up to a Grid and certain fields are required, but the internal field names are not exactly fit for display. So, if I have a field named 'user_first_name': rather than a message like: 'user_first_name is required' I'd like an easy way to specify an alias for the field name to produce 'First name is required'

    I know it's possible to define custom validation messages, but the standard messages are generally fine, except for the field names. It seems like a lot of work to define loads of custom messages, when all I need is to replace the field name.

    Any suggestions?
  2. Answer
    Iliana Nikolova
    Admin
    Iliana Nikolova avatar
    2592 posts

    Posted 29 Mar 2013 Link to this post

    Hi Mat,

    In order to achieve this you can specify the required validation message in the schema. For example:
    dataSource = new kendo.data.DataSource({
      //....
      schema: {
          model: {
             id: "ProductID",
             fields: {
                  ProductID: { editable: false, nullable: true },
                  FirstName: { validation: { required: {message: "First name is required"} } },
             }
           }
        }
    });
    Let me know if this fits your requirements.
     
    Regards,
    Iliana Nikolova
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. M
    M avatar
    29 posts
    Member since:
    Oct 2012

    Posted 02 Apr 2013 Link to this post

    Not sure how I missed that in the documentation... that's simple enough.

    Thanks.
  5. Pranami
    Pranami avatar
    4 posts
    Member since:
    May 2014

    Posted 19 May 2014 Link to this post

    How do I write the same in PHP?
  6. Pranami
    Pranami avatar
    4 posts
    Member since:
    May 2014

    Posted 19 May 2014 in reply to Pranami Link to this post

    I found out, wrote it as:

    $descriptionField->type('string')
                     ->validation(
    array
                         (
    'required' => array
                                (true,

                                'message'
    =>'Description is required'
                                )
                         )
                     );
  7. Elko
    Elko avatar
    23 posts
    Member since:
    Dec 2012

    Posted 27 May 2015 Link to this post

    Hi!

    I just want to ask: Is this still the current state of developement? Or is it now possible to use the standard-messages in combination with the labels of the grid-columns...? Defining custom-messages for all columns is time-consuming.

    Best Regards!

  8. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 29 May 2015 Link to this post

    Hello Elko,

    There are no changes in that regard, as the Validator is not tightly coupled with the Grid and there is no built-in mechanism of using the column's title instead of the field's name.

    Regards,
    Alexander Popov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready