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

ajax created checkbox added to existing checkboxes #149

Closed
dblado opened this issue Mar 19, 2014 · 4 comments
Closed

ajax created checkbox added to existing checkboxes #149

dblado opened this issue Mar 19, 2014 · 4 comments

Comments

@dblado
Copy link

dblado commented Mar 19, 2014

I have a set of checkboxes and an 'add another button' that creates the new record, and inserts the new checkbox (unstyled) into the DOM.

I've looked at #37 and #60 but still can't figure out how to do this right.

If I do something like this:

    insert = '<div class="col-md-4">' \
             '<label class="checkbox">' \
             '<input type="checkbox" checked name="good_at" value="' + str(new_proficiency.pk) + '">' \
                                                                                                 '' + new_proficiency.name + '' \
                                                                                                                             '</label>' \
                                                                                                                             '</div>'

append('#id_proficiencies', 'innerHTML', insert)

$("#write_review_form input[value=\'' + str(
        new_proficiency.pk) + '\']").iCheck({checkboxClass: "icheckbox_minimal checked",radioClass: "iradio_minimal", increaseArea: "20%"});'

only the new checkbox is clickable -- the other checkboxes are set to true|false as they are clicked but no UI updates to show the user.

if I do this instead:

$(document).trigger(\'icheck\');

all the UI is right and the true|false is updated but all previous checked items are unchecked.

any way to retain the checked state of each checkbox while adding a new checkbox programmatically?

@drgullin
Copy link
Owner

Hello David.

I need to see a demo, to figure out what actually happens.

Have you tried 2.x version?

19 Mar 2014, â 04:28, David Blado notifications@github.com íàïèñàë(à):

I have a set of checkboxes and an 'add another button' that creates the new record, and inserts the new checkbox (unstyled) into the DOM.

I've looked at #37 and #60 but still can't figure out how to do this right.

If I do something like this:

insert = '<div class="col-md-4">' \
         '<label class="checkbox">' \
         '<input type="checkbox" checked name="good_at" value="' + str(new_proficiency.pk) + '">' \
                                                                                             '' + new_proficiency.name + '' \
                                                                                                                         '</label>' \
                                                                                                                         '</div>'

append('#id_proficiencies', 'innerHTML', insert)

$("#write_review_form input[value='' + str(
new_proficiency.pk) + '']").iCheck({checkboxClass: "icheckbox_minimal checked",radioClass: "iradio_minimal", increaseArea: "20%"});'
only the new checkbox is clickable -- the other checkboxes are set to true|false as they are clicked but no UI updates to show the user.

if I do this instead:

$(document).trigger('icheck');
all the UI is right and the true|false is updated but all previous checked items are unchecked.

any way to retain the checked state of each checkbox while adding a new checkbox programmatically?


Reply to this email directly or view it on GitHub.

@dblado
Copy link
Author

dblado commented Mar 19, 2014

hi, trying to reproduce w/out ajax but it's working fine :(

I did notice that when I run $(document).trigger('icheck'); only after inserting

image

seems every time I insert a checkbox and run the trigger, it creates unnecessary elements

@dblado
Copy link
Author

dblado commented Mar 19, 2014

ok, good news, I removed all the processing to callbacks in my JS instead of trying to use the builtin ones in the ajax library I'm using. works fine now. Not sure what was causing the above but I'm moving on now :)

Thanks for the quick response -- and thanks for this awesome library.

@dblado dblado closed this as completed Mar 19, 2014
@dblado
Copy link
Author

dblado commented Mar 19, 2014

hopefully someone else finds this useful :)

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