• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

checked radio button from an Enum value

 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried doing a search first cause I was sure that this had to have been discussed upteen times.

I have a json value coming back with information. One property is set via an Enum in Java, so in the json it is just a String. Based on that String I want to set my radio buttons to have the one checked for that value. I am using Mustache/ICanHaz templating that is generating the radio buttons, but all I will have in the template is {{visibility}} basically the String value and there isn't any javascript in the template., the template is rendered from JavaScript and the html is stored in a var before I add it to a div via html(contentsFromTemplateRendering).

Thanks

With all your help I have been making some great progress on my app. I might one day call myself a web developer. But very quietly so no one else hears.

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for bumping this, but I still haven't found any solution on Google or in testing things.

Thanks

Mark
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure anyone else here has even heard of the tools that you are using. So not surprising that it's been rather quiet.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does the code look like for generating the radio buttons?

Eric
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The HTML still looks the same, so the part about ICanHaz only has an affect that I get the String value via its name {{visibility}} which just gets replaced with the value from the JSON.

Here is the HTML



Here is a picture of the radio buttons in the FancyBox I use.

Bear - I was thinking that people didn't answer because it was such and easy solution that it was a dumb question that everyone thought I was just plain lazy. ;)

Thanks

Mark

RadioBtns.png
[Thumbnail for RadioBtns.png]
Pyramid of Radio Buttons
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also need to make that fancybox wider.

Mark
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spent 5 minutes looking at the framework, looks like you need to do something like this.



and the HTML



Sucks having to add that into your object, but hey, nothing is pretty in the JS world.

You might want to ask someone that actually knows this framework better than me with 5 minutes of knowledge.

Eric
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, that is pretty looking. Yeah the high level variable "temp" isn't pretty, but the rest is slick. It is why you are the expert and me just the learner.

"Sucks having to add that into your object"

Do you mean the js code into the template/html? or that goes in one of my .js files, or included in my json. The JSON doesn't sound right, but I think you mean in my template. Unless you tell me otherwise.

Thanks again

Mark
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I rather see something like



or



Eric
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:I rather see something like



or



Eric



Or more like
<input {{visibilityFunction()}}/>

where the visibilityFunction is part of the JSON object. iCanHaz and mustache allows functions in data objects and calling them from the template. Looks like I will go down that path of adding a function after I get the data from the server.

Thanks

Mark
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well functions are not in JSON, adding the function turns it into an object literal. Run it through JSON.parse() and you will be out of luck.

Another reason why I do not like it my solution.

Eric
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:Well functions are not in JSON, adding the function turns it into an object literal. Run it through JSON.parse() and you will be out of luck.

Another reason why I do not like it my solution.

Eric



Actually the template takes an object, so with that var holding that object I can add a function. When I retrieve the JSON from JQuery .post call it is assigned to a var, which I can then add the function

https://github.com/janl/mustache.js/
See functions section, if you are curious.

So it would be possible.

Thanks

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic