Customeditortemplate checkbox with default value only in Add mode not in edit

3 posts, 0 answers
  1. Anamika
    Anamika avatar
    157 posts
    Member since:
    Mar 2014

    Posted 16 Sep 2014 Link to this post

    Hello,

    I am using customeditortemplate with a checkbox for SaveinOutlook. taskViewModel has boolean property IsSavedInOutlook and Models.Utility.SaveInOutlook is the default value for add events. My customeditortemplate checkbox is as below
    <div class="k-edit-label">
        @(Html.LabelFor(model => model.IsSavedInOutlook))
    </div>
    <div data-container-for="isSavedInOutlook" class="k-edit-field">
        @if (//add event?? Models.Utility.SaveInOutlook == true)
    {
       <input data-bind="checked: isSavedInOutlook" data-val="true" id="IsSavedInOutlook" name="IsSavedInOutlook" type="checkbox" checked/>
    } else{
             <input data-bind="checked: isSavedInOutlook" data-val="true" id="IsSavedInOutlook" name="IsSavedInOutlook" type="checkbox" />
    }        

    </div>

    is there a way i can differenciate it is add event or edit event and set checked based on  Models.Utility.SaveInOutlook value? When the customedittemplate popup window comes do a have a way to check add/edit mode and set a default value?

    Anamika
  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3748 posts

    Posted 18 Sep 2014 Link to this post

    Hello Anamika,

    You can determine whether event is added or edited in the edit event of the widget (Edit method for ASP.NET MVC wrapper). In the edit event handler, you can determine whether a new event is added and thus set the isSavedInOutlook field to true or false using the model set method. The event handler should look like something like this:
    function edit(e) {
      var event = e.event;
     
      if (event.isNew()) { //event is new (just added)
         event.set("isSavedInOutlook", true);
      }
    }

    Regards,
    Georgi Krustev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Anamika
    Anamika avatar
    157 posts
    Member since:
    Mar 2014

    Posted 18 Sep 2014 in reply to Georgi Krustev Link to this post

    thanks that solves my problem.
Back to Top