Setting recurrance messages from variable

4 posts, 0 answers
  1. Rob
    Rob avatar
    61 posts
    Member since:
    Jan 2012

    Posted 26 Oct 2016 Link to this post

    Hi Guys

    I'm sure this is just a syntax issue.. but I'm stuffed if I can work it out. 

    If I set my messages ( for testing only) like this in the editor template it works fine.

    <div data-container-For="recurrenceRule" Class="k-edit-field">
        <div data-bind="value:recurrenceRule" name="recurrenceRule" data-role="recurrenceeditor" data-frequencies="['never','daily','weekly']" data-messages="{'frequencies':{'never':'Nie','daily':'Täglich','weekly':'Wöchentlich','monthly':'Monatlich','yearly':'Jährlich'}}"></div>
    </div>

     

    But if I try to set the data-messages to a javascript variable I can't get it to work. ( I wan't to do this as I want to be able to change the language based on the browser language.. so I want to have an externally defined message object.)

    I've tried all sorts of ways to define the variable.. but it never works

      var rmessages = {'frequencies':{'never':'Nie','daily':'Täglich','weekly':'Wöchentlich','monthly':'Monatlich','yearly':'Jährlich'}};
      // var rmessages  = {frequencies:{never:"Nie",daily:"Täglich",weekly:"Wöchentlich",monthly:"Monatlich",yearly:"Jährlich"}};
     
    //-------------------------------
    <div data-container-For="recurrenceRule" Class="k-edit-field">
            <div data-bind="value:recurrenceRule" name="recurrenceRule" data-role="recurrenceeditor" data-frequencies="['never','daily','weekly']" data-messages="rmessages"></div>
        </div>

     

    When I run , it seems that the data-messages are set to 'rmessages'  ( as per the attached image) however is other parts of the same template I refer to javascript variable and this works. ( e.g setting the  'data-source' for this drop down which is on the same template.

    <div id="selectsg" style="display:none;">
           <div Class="k-edit-label"><label for="SGIDId">Queue</label></div>
           <div data-container-For="SGID" Class="k-edit-field">
               <input name="SGIDId" type="text" id="SGIDId" data-role="combobox" data-source="sgdataSource" data-text-field="name" data-value-field="id" data-bind="value:SGID" data-placeholder="Select Queue..." data-value-primitive="true" />
           </div>
       </div>

     

    Can someone please point out my stupid error in syntax or thinking!  

    Many thanks

    Rob

     

     

     

    asdad

     

  2. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    363 posts

    Posted 28 Oct 2016 Link to this post

    Hello Rob,

    I am afraid that the editor template, would not allow you to achieve the required implementation. However, as this scenario could be also applicable in other projects too, I would suggest you to log a Feature request in our Feedback portal.

    Regards,
    Veselin Tsvetanov
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
  3. Rob
    Rob avatar
    61 posts
    Member since:
    Jan 2012

    Posted 12 Dec 2016 Link to this post

    I came back to this as the customer really needed a solution which provided different language support.

    I found a way to achieve this and thought I post here for anyone with the same requirement. I created a shared function on the server ( VB.NET) for the translation of strings (using standard globalization and resource files) then managed to get the syntax right to create the  data-messages object using razor in the template.

    Note I am not providing monthly or yearly, so I just set those to English.

     

    <div data-container-For="recurrenceRule" Class="k-edit-field">
           <div data-bind="value:recurrenceRule" name="recurrenceRule" data-role="recurrenceeditor" data-frequencies="['never','daily','weekly']"  data-messages={'frequencies':{'never':'#='@Html.Raw(TranslateShare.translate("never"))'#','daily':'#='@Html.Raw(TranslateShare.translate("daily"))'#','weekly':'#='@Html.Raw(TranslateShare.translate("weekly"))'#','monthly':'monthly','yearly':'yearly'}} ></div>
       </div>
  4. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    363 posts

    Posted 13 Dec 2016 Link to this post

    Hello Rob,

    Thank you for shearing with us the approach that helped you resolve the issue faced. As a small token of gratitude for sharing your solution with the community, I have updated your Telerik points.

    Regards,
    Veselin Tsvetanov
    Telerik by Progress
    Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
Back to Top