aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes checked radio button from an Enum value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "checked radio button from an Enum value" Watch "checked radio button from an Enum value" New topic
Author

checked radio button from an Enum value

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Sorry for bumping this, but I still haven't found any solution on Google or in testing things.

Thanks

Mark
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
What does the code look like for generating the radio buttons?

Eric
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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




[Thumbnail for RadioBtns.png]

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

I also need to make that fancybox wider.

Mark
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I rather see something like



or



Eric
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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
 
Consider Paul's rocket mass heater.
 
subject: checked radio button from an Enum value
 
Similar Threads
setting a page element
Make Checkbox group Non-Editable
Radio Buttons
Struts 1.1: html:radio issues
checkbox