This is a migrated thread and some comments may be shown as answers.

Override field name for validation display

6 Answers 586 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
M
Top achievements
Rank 1
M asked on 28 Mar 2013, 12:09 PM
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?

6 Answers, 1 is accepted

Sort by
0
Accepted
Iliana Dyankova
Telerik team
answered on 29 Mar 2013, 04:41 PM
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!
0
M
Top achievements
Rank 1
answered on 02 Apr 2013, 10:56 AM
Not sure how I missed that in the documentation... that's simple enough.

Thanks.
0
Pranami
Top achievements
Rank 1
answered on 20 May 2014, 04:30 AM
How do I write the same in PHP?
0
Pranami
Top achievements
Rank 1
answered on 20 May 2014, 04:49 AM
I found out, wrote it as:

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

                            'message'
=>'Description is required'
                            )
                     )
                 );
0
Elko
Top achievements
Rank 1
answered on 27 May 2015, 03:01 PM

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!

0
Alexander Popov
Telerik team
answered on 29 May 2015, 03:14 PM
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!
 
Tags
Data Source
Asked by
M
Top achievements
Rank 1
Answers by
Iliana Dyankova
Telerik team
M
Top achievements
Rank 1
Pranami
Top achievements
Rank 1
Elko
Top achievements
Rank 1
Alexander Popov
Telerik team
Share this question
or