Showing posts with label Add radio input dynamically to jQuery Mobile fieldset controlgroup. Show all posts
Showing posts with label Add radio input dynamically to jQuery Mobile fieldset controlgroup. Show all posts

Wednesday, October 2, 2013

Add radio input dynamically to jQuery Mobile fieldset controlgroup

I’ve seen variations on this question yet not my specific case on SO, so here goes.

I’m having trouble adding a new radio input dynamically to an existing control group using jQuery Mobile. It will add, yet the style is not correct & it doesn’t appear to interact with the other inputs correctly.

Here’s my fiddle:
http://jsfiddle.net/cjindustries/3mQF6/

Can anyone see what I’m doing wrong? Or is is a case of regenerating the whole fieldset /controlgroup again? 🙁

Thanks! Code below too…

        <div id="testPage" data-role="page">        <div data-role="content">    <fieldset data-role="controlgroup">        <legend>Radio buttons, vertical controlgroup:</legend>            <input type="radio" name="radio-choice-1" id="radio-choice-1" value="choice-1" checked="checked">            <label for="radio-choice-1">Cat</label>            <input type="radio" name="radio-choice-1" id="radio-choice-2" value="choice-2">            <label for="radio-choice-2">Dog</label>            <input type="radio" name="radio-choice-1" id="radio-choice-3" value="choice-3">            <label for="radio-choice-3">Hamster</label>            <input type="radio" name="radio-choice-1" id="radio-choice-4" value="choice-4">            <label for="radio-choice-4">Lizard</label>    </fieldset>        </div>    </div>$('<input type="radio" name="radio-choice-5" id="radio-choice-5"><label for="radio-choice-5">Horse</label>')    .appendTo("fieldset");$("fieldset").trigger('create');

You need to use name="radio-choice-1" as you have used in above. This solves you behavior problem

Behavior problem solved with below change
Your modified code for dynamically adding radio.

 $('<input type="radio" name="radio-choice-1" id="radio-choice-5"><label for="radio-choice-5">Horse</label>').appendTo("fieldset");

Style problem solved with below change
Just recreate div instead of fieldset

 $("div").trigger('create');

Check Fiddle Demo

Friday, September 27, 2013

What is the difference when assigning a bash variable value with this syntax?

Sorry if this is something really simple or has already been asked, yet due to the nature of the question I cannot think of any search terms to put on search engines.

Lately I have seen some bash scripts that they assign variable values like this:

$ MY_BASH_VAR=${MY_BASH_VAR:-myvalue}$ echo "$MY_BASH_VAR"myvalue

What is the difference from the most usual way of assigning a value like this:

MY_BASH_VAR=myvalue$ echo "$MY_BASH_VAR"myvalue

You can look at http://linux.die.net/man/1/bash

${parameter:-word}  Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.

This provides a default value : MY_BASH_VAR keeps its value if defined otherwise, it takes the default “myvalue”

bruce@lorien:~$ A=42bruce@lorien:~$ A=${A:-5}bruce@lorien:~$ echo $A42