Kendo scheduler add validation for dropdown list resouces dataSource

8 posts, 0 answers
  1. Lam
    Lam avatar
    6 posts
    Member since:
    Feb 2016

    Posted 19 Oct Link to this post

    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.
  2. Tyler
    Tyler avatar
    31 posts
    Member since:
    Feb 2017

    Posted 19 Oct in reply to Lam Link to this post

    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. 

  3. Joana
    Admin
    Joana avatar
    134 posts

    Posted 23 Oct Link to this post

    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.
  4. Lam
    Lam avatar
    6 posts
    Member since:
    Feb 2016

    Posted 23 Oct Link to this post

    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.
  5. Joana
    Admin
    Joana avatar
    134 posts

    Posted 25 Oct Link to this post

    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.
  6. Lam
    Lam avatar
    6 posts
    Member since:
    Feb 2016

    Posted 09 Nov in reply to Joana Link to this post

    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

  7. Tyler
    Tyler avatar
    31 posts
    Member since:
    Feb 2017

    Posted 09 Nov in reply to Lam Link to this post

    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.

  8. Lam
    Lam avatar
    6 posts
    Member since:
    Feb 2016

    Posted 09 Nov in reply to Tyler Link to this post

    It works fine now, that's correct i'm looking for. Thanks a lots of for saving my time, Tyler.
Back to Top