Skip to content
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

BUG? radio uncheckable dinamically? #168

Open
gine opened this issue Sep 24, 2013 · 4 comments
Open

BUG? radio uncheckable dinamically? #168

gine opened this issue Sep 24, 2013 · 4 comments

Comments

@gine
Copy link

gine commented Sep 24, 2013

I try to fill the form this is how i create it :

<label><input  type="radio" id="ruolo_ditta-0" name="ruolo_ditta">Cliente</label>
<label><input  type="radio" id="ruolo_ditta-1" name="ruolo_ditta">Fornitore</label>

and how i set this field:

inputs: {
        ...
        'ruolo_ditta' : {
            filters: 'required min',
            data: { min: 1 },
        }, 
        ...

I want fill my form dinamically and radio is the only field unsettable. This is the field elaborate by jq-idealform:

<div class="ideal-wrap">
<label class="ideal-label" style="width: 129px;">Ruolo ditta:</label>
<span class="ideal-field ideal-radiocheck">
<label class="ideal-radiocheck-label" onclick="">
<input id="ruolo_ditta-0" class="_input" type="radio" name="ruolo_ditta" style="position: absolute; left: -9999px;" autocomplete="off">
<span class="ideal-radio"></span>
Cliente
</label>
<label class="ideal-radiocheck-label" onclick="">
<input id="ruolo_ditta-1" class="_input" type="radio" name="ruolo_ditta" style="position: absolute; left: -9999px;" autocomplete="off">
<span class="ideal-radio"></span>
Fornitore
</label>
<i class="ideal-icon ideal-icon-valid" style="display: none;"></i>
<i class="ideal-icon ideal-icon-invalid" style="display: block;"></i>
</span>
<span class="ideal-error" style="display: none;">
Check at least
<strong>1</strong>
options.
</span>
</div>

And here.. it's how i try to fill it, where $(this) is the first input element

$(this).next().addClass('checked');
$(this).parent().parent().addClass('valid');

first $(this) from firebug: Object[span.ideal-radio]
second $(this) from firebug: Object[span.ideal-field]

@gine
Copy link
Author

gine commented Sep 26, 2013

No i can't select the first radio button whit html too, it's auto selectable only the second. here the code:

<html>
<head>
    <script src="js/lib/jquery-1.8.2.min.js"></script>
    <link rel="stylesheet" href="css/jquery.idealforms.min.css" media="screen"/>
    <script src="js/lib/jquery.idealforms.min.js"></script> <!-- removing it work -->
<head>
<body>
    <form id="form-doc" method="post" action="">
    <div>
        <label>Tipo doc:</label> 
        <input type="text" name="tipo_doc" />
    </div>
    <div>
        <label>Ruolo ditta:</label> 
        <label> 
            <input type="radio" name="ruolo_ditta" checked/>Fornitore
        </label> 
        <label> 
            <input type="radio" name="ruolo_ditta" /> Cliente
        </label>
    </div>
    <div>
        <button type="submit">Salva</button>
        <button id="reset" type="button">Reset</button>
    </div>
    </form>
    <script type="text/javascript">
    var options = {
        onFail: function() {alert( 'fail');},
        onSuccess: function() {alert( 'succes');},
        inputs: {
            'tipo_doc' : {
                filters: 'required min max',
                data: { min: 3, max: 16 },
            }, 
            'ruolo_ditta' : {
                filters: 'required min',
                data: { min: 1 },
            }, 
        }
    };
    var myform = $('#form-doc').idealforms(options).data('idealforms');
    $('#reset').click(function(){
        myform.reset().fresh().focusFirst();
    });
    myform.focusFirst();
</script>`
</body>
</html>

@gine
Copy link
Author

gine commented Sep 26, 2013

Documentation is wrong for radio button.

The field is required. This filter ONLY works with text inputs (text, password, textarea). For select use exclude to exclude the default option. For radio and checkbox use min: 1 which will require at least one option to be checked.

But using:

'ruolo_ditta' : {
    filters: 'min',
    data: { min: 1 },
}

or combinated whit 'required' filters (or only required filter) on idealforms option, where "ruolo_ditta" is the value of attribute name of radio elements. The form make a wrong and realy strange behavior.

Deleting it, using checked on the first radio html element works good and

$(this).prop('checked', true).trigger('change'); 

works as aspected.

I suggest to verify if it's a BUG

@elclanrs
Copy link
Owner

elclanrs commented Oct 6, 2013

I just released Ideal Forms 3, please try to see if it works in the new version. You'd have to change the markup since it's not compatible with Ideal Forms 2. Once you have it setup try:

$('form').idealforms({
  rules: {
    'ruolo_ditta': 'minoption:1'
  }
});

And to check/uncheck it dynamically a click() event should work fine:

$radio.click();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants