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

Kendo scheduler add validation for dropdown list resouces dataSource

7 Answers 403 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Lam
Top achievements
Rank 1
Lam asked on 19 Oct 2017, 06:29 PM

Hi,

 

I would like to validate the dropdown list dataSource in resouces:

resources: [{
  field: "ownerId",
  title: "Patient",
  validation: {
    required: true
  },
  dataSource: patientList
}]

But i didn't see it when create new event.  So, how can i validate it before create new event? and custom message validation error if it has?
P/s: I have tried to added the attribute required="required" to the select, it validate OK, but i can't save to create new event, even i have picked one from the list.

7 Answers, 1 is accepted

Sort by
0
Tyler
Top achievements
Rank 1
answered on 19 Oct 2017, 07:18 PM

This dojo provides an example of custom validation. I set up my own rule for the ownerId input (it has to be Charlie, which has value 3 in that example), and my own message for if the validation fails. 

You will want to utilize a custom editor template for this, which gives you greater control and flexibility. 

Custom editor template example

Validator documentation

you could potentially create a validator on the built in pop up editor, but grabbing the fields to check validation on will be much more difficult. 

If you just want to check if the field is populated, just add a required attribute, a data-required-msg attribute, and then:

$('#editorWrapper').kendoValidator();

Then just call validate() with that and it easily determines if the field has a value, and if not, prevents the user from continuing. 

0
Joana
Telerik team
answered on 23 Oct 2017, 02:10 PM
Hi Lam,

Tyler has already provided great examples for your scenario. I could add that you could also take reference to the built in validator in the scheduler and set custom validation rules and messages. Here are articles illustrating it:

https://docs.telerik.com/kendo-ui/controls/scheduling/scheduler/how-to/validation/getting-reference-to-the-validator

https://docs.telerik.com/kendo-ui/api/javascript/ui/validator

Regards,
Joana
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Lam
Top achievements
Rank 1
answered on 23 Oct 2017, 03:30 PM
Thanks all of you, I temporary using an not good solution:
I added required attribute and message to the dropdown list and added event onchange, and remove the attr require if the dropdown list has value (when user pick one).

I'll check your solution to build custom validator and message.
0
Joana
Telerik team
answered on 25 Oct 2017, 02:01 PM
Hi Lam,

Let us know if you have any other question regarding the implementation of custom validator.

Regards,
Joana
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Lam
Top achievements
Rank 1
answered on 09 Nov 2017, 10:05 AM

Hi Joan,

 

I have tried to implement kendo validator, but seems it doesn't work:
Please check it on: http://dojo.telerik.com/@n2lose/ohagI
As i have checked in the DOM, i saw select roomId has attribute require and title, when i click on save, it validated but don't show the message?
Could you tell me what's wrong? Thanks

 

Regards,

Lam

0
Tyler
Top achievements
Rank 1
answered on 09 Nov 2017, 02:56 PM

You need the 'name' attribute on your elements in order to see the validator message for your custom fields.

This Dojo has your scheduler working and I can see validation messages for the title and roomId fields. All that was changed as adding a 

name: roomId

to your roomId field in the schema setup.

0
Lam
Top achievements
Rank 1
answered on 09 Nov 2017, 03:12 PM
It works fine now, that's correct i'm looking for. Thanks a lots of for saving my time, Tyler.
Tags
Scheduler
Asked by
Lam
Top achievements
Rank 1
Answers by
Tyler
Top achievements
Rank 1
Joana
Telerik team
Lam
Top achievements
Rank 1
Share this question
or