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

Setting recurrance messages from variable

3 Answers 63 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
Rob asked on 27 Oct 2016, 01:40 AM

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

 

3 Answers, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 28 Oct 2016, 02:44 PM
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.
0
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 12 Dec 2016, 08:54 PM

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>
0
Veselin Tsvetanov
Telerik team
answered on 13 Dec 2016, 08:01 AM
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.
Tags
Scheduler
Asked by
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Veselin Tsvetanov
Telerik team
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or