radio button selected value in widget

UjjwalKumaG
Tera Contributor

Hi,

Used Radio buttons widget:

<label><input type="radio" name="food_preference" ng-model="data.veg"> Veg</label><br>
<label><input type="radio" name="food_preference" ng-model="data.nonVeg"> Non Veg</label><br>
<label><input type="radio" name="food_preference" ng-model="data.others"> Others</label><br>

 I tried below code, but it is coming as undefined

$scope.data.veg

Please suggest , how to get value which radio is selected.

 

Thanks 

Ujjwal

1 ACCEPTED SOLUTION

potatoBOY
Giga Contributor


"Your use of the Radio Buttons widget looks great! However, you might run into issues with the ng-model binding since all three options are bound to different properties (data.veg, data.nonVeg, data.others). For proper functionality, they should share the same ng-model and be differentiated by their value attributes. For example:

html
Copy code
<label><input type="radio" name="food_preference" ng-model="data.preference" value="Veg"> Veg</label><br>
<label><input type="radio" name="food_preference" ng-model="data.preference" value="NonVeg"> Non Veg</label><br>
<label><input type="radio" name="food_preference" ng-model="data.preference" value="Others"> Others</label><br>
This way, you can capture the selected option in data.preference.

By the way, if you're ever looking for reliable solutions for structural issues, here's a useful resource on flat roof repair Utah."

View solution in original post

3 REPLIES 3

potatoBOY
Giga Contributor
 

"Your use of the Radio Buttons widget looks great! However, you might run into issues with the ng-model binding since all three options are bound to different properties (data.veg, data.nonVeg, data.others). For proper functionality, they should share the same ng-model and be differentiated by their value attributes. For example:

html
Copy code
<label><input type="radio" name="food_preference" ng-model="data.preference" value="Veg"> Veg</label><br> <label><input type="radio" name="food_preference" ng-model="data.preference" value="NonVeg"> Non Veg</label><br> <label><input type="radio" name="food_preference" ng-model="data.preference" value="Others"> Others</label><br>

This way, you can capture the selected option in data.preference.

By the way, if you're ever looking for reliable solutions for structural issues, here's a useful resource on flat roof repair Utah ."

hi @potatoBOY  - thanks for solution

potatoBOY
Giga Contributor


"Your use of the Radio Buttons widget looks great! However, you might run into issues with the ng-model binding since all three options are bound to different properties (data.veg, data.nonVeg, data.others). For proper functionality, they should share the same ng-model and be differentiated by their value attributes. For example:

html
Copy code
<label><input type="radio" name="food_preference" ng-model="data.preference" value="Veg"> Veg</label><br>
<label><input type="radio" name="food_preference" ng-model="data.preference" value="NonVeg"> Non Veg</label><br>
<label><input type="radio" name="food_preference" ng-model="data.preference" value="Others"> Others</label><br>
This way, you can capture the selected option in data.preference.

By the way, if you're ever looking for reliable solutions for structural issues, here's a useful resource on flat roof repair Utah."