javascript - How to detect change in form if added a new row in prime faces datatable -
i have requirements disable save , cancel buttons in page on page load. should enable save , cancel buttons if user changes in page. achieve this, using
http://plugins.jquery.com/are-you-sure/
this plugin working fine there need customization in many scenarios, 1 below
i have page item groups consists of 3 panels.
leftpanel : list of item groups in system
centerpanel : list of items assigned selected item group
rightpanel : list of items assign item group
now assume have datatable
<p:datatable var="itms" value="#{mybean.listofitems}" rows="10" paginator="true" paginatortemplate="{currentpagereport} {firstpagelink} {previouspagelink} {pagelinks} {nextpagelink} {lastpagelink} {rowsperpagedropdown}" rowsperpagetemplate="10,50,100"> </p:datatable>
to assign items item group select items in right panel , click on assign button add listofitems show in center panel
listofitems.addall(selecteditems);
i calling rescan method defined in plugin on assign button oncomplete
detect changes , track new records added because want consider addition or removal of fields change.
now on page load if item group selected , has 13 items assigned see first page 10 records. if items added added in list @ end list. since i'm in first page , page having complete rows plugin unable find changes in form.
how find change in scenario.
since want consider addition or removal of fields change make sure users save changes, 1 way this:
you can have hidden input:
<h:inputhidden id="hiddeninput" />
and in assign button oncomplete
mentioned can add:
oncomplete="$('#hiddeninput').val('dirty').change();"
this add 'dirty' string (for example) hidden input , call change()
tell plugin changed, , plugin mark form dirty (changed).
and in oncomplete
of saving button, have clear value , reinitialize plugin start again:
oncomplete="$('#hiddeninput').val('');$('#formid').trigger('reinitialize.areyousure');"
also add checking or @ end of action (link).
note: if add , delete same 'item', technically there aren't changes, want keep form changed right? solution work that. correct me if i'm wrong , want manage particular case. have add logic in compare old , new values , clear or dirty hidden input accordingly.
Comments
Post a Comment