-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Radio & Checkbox Inputs #117
Comments
Can you put the desired html please? |
I would expect output HTML below by default. Again, if anyone knows of docs, examples, or special directives I would appreciate it. JavaScript: var data = {
radio: 'TWO',
checkbox: ['THREE', 'FOUR'],
};
$(function () {
$('#theForm').render(data);
}) Input:<form id="theForm">
<h3>Radio Buttons</h3>
<input data-bind="radio" type="radio" name="rdo" value="ONE" />ONE
<br>
<input data-bind="radio" type="radio" name="rdo" value="TWO" />TWO
<br>
<input data-bind="radio" type="radio" name="rdo" value="THREE" />THREE
<br><br>
<h3>Check Boxes</h3>
<table cellpadding="10">
<tbody><tr>
<td><input data-bind="checkbox" type="checkbox" name="chkbox" value="ONE" />ONE</td>
<td><input data-bind="checkbox" type="checkbox" name="chkbox" value="TWO" />TWO</td>
<td><input data-bind="checkbox" type="checkbox" name="chkbox" value="THREE" />THREE</td>
<td><input data-bind="checkbox" type="checkbox" name="chkbox" value="FOUR" />FOUR</td>
</tr></tbody></table>
</form> Output:<form id="theForm">
<h3>Radio Buttons</h3>
<input data-bind="radio" type="radio" name="radio" value="ONE" />ONE
<br>
<input data-bind="radio" type="radio" name="radio" value="TWO" checked="checked" />TWO
<br>
<input data-bind="radio" type="radio" name="radio" value="THREE" / >THREE
<br><br>
<h3>Check Boxes</h3>
<table cellpadding="10">
<tbody><tr>
<td><input data-bind="checkbox" type="checkbox" name="chkbox" value="ONE" />ONE</td>
<td><input data-bind="checkbox" type="checkbox" name="chkbox" value="TWO" />TWO</td>
<td><input data-bind="checkbox" type="checkbox" name="chkbox" value="THREE" checked="checked" />THREE</td>
<td><input data-bind="checkbox" type="checkbox" name="chkbox" value="FOUR" checked="checked" />FOUR</td>
</tr></tbody></table>
</form> Thanks for any help you can provide! |
you are trying to use the tag name as id to insert the text and paramaters, si not posible, look the next example: javascript for the form var inputs = {
'label1' : 'this is a text',
'label2' : 'other one',
'checked1': 'checked'
}
var directives = {
'checked1': {
'checked': function(){
return this.checked1;
}
}
}
$('form').render(inputs, directives) html markup <form>
<input type="checkbox" id="checked1"><label for="checked1" id="label1"></label>
<input type="checkbox" id="checked2"><label for="checked2" id="label2"></label>
</form> html output <form>
<input type="checkbox" id="checked1" checked="checked"><label for="checked1" id="label1">this is a text</label>
<input type="checkbox" id="checked2"><label for="checked2" id="label2">other one</label>
</form> |
Thanks @grimaldo! But...
I would expect the checkboxes, radio buttons to check themselves based on the data passed in. In my case the templates will have the labels hard coded in the HTML. I am not dynamically building the form, but I am dynamically "filling it in". I have revamped my inputs/outputs: JavaScript: <script>
var data = {
quantity: 3,
colors: ['GREEN', 'YELLOW'],
};
$(function () {
$('#theForm').render(data);
})
</script> Input HTML<form id="theForm">
<h3>Quantity: Radio Buttons</h3>
<input data-bind="quantity" type="radio" name="rdos" value="2" />2<br>
<input data-bind="quantity" type="radio" name="rdos" value="3" />3<br>
<input data-bind="quantity" type="radio" name="rdos" value="5" />5<br>
<br>
<h3>Colors: Check Boxes</h3>
<input data-bind="colors" type="checkbox" name="chkbxs" value="RED" />RED<br>
<input data-bind="colors" type="checkbox" name="chkbxs" value="GREEN" />GREEN<br>
<input data-bind="colors" type="checkbox" name="chkbxs" value="BLUE" />BLUE<br>
<input data-bind="colors" type="checkbox" name="chkbxs" value="YELLOW" />YELLOW<br>
<br>
</form> Expected Output HTML<form id="theForm">
<h3>Quantity: Radio Buttons</h3>
<input data-bind="quantity" type="radio" name="rdos" value="2" />2<br>
<input data-bind="quantity" type="radio" name="rdos" value="3" checked="checked" />3<br>
<input data-bind="quantity" type="radio" name="rdos" value="5" />5<br>
<br>
<h3>Colors: Check Boxes</h3>
<input data-bind="colors" type="checkbox" name="chkbxs" value="RED" />RED<br>
<input data-bind="colors" type="checkbox" name="chkbxs" value="GREEN" checked="checked" />GREEN<br>
<input data-bind="colors" type="checkbox" name="chkbxs" value="BLUE" />BLUE<br>
<input data-bind="colors" type="checkbox" name="chkbxs" value="YELLOW" checked="checked" />YELLOW<br>
<br>
</form> |
Hi @heme , Did you ever find a solution for this? It works for me for checkboxes, but not for radios. Thanks! |
In case anyone else has this same struggle, adding a directive worked for me:
|
It has been a while since I first posted this, and I'm no longer actively using transparency, but.... I don't think I wanted to write a directive for every radio/checkbox group in my app. I was hoping this could get baked into the framework in some way. I do realize checkboxes are used as a single input and as a group; I'm sure that presents a challenge. Good on ya for jumping in here. I really enjoyed working with this lib. |
Is there documentation on HTML form inputs somewhere? Specifically Checkboxes and Radio buttons. The code below is not working as expected for me. Thank you!
The text was updated successfully, but these errors were encountered: