File modules/template_engine/components/html/component_checkbox/checkbox.js

Last commit: Thu Mar 10 13:09:06 2022 +0100	dankert	New: Remember some user inputs in the browser local storage.
1 import $ from '../../../../cms/ui/themes/default/script/jquery-global.js'; 2 import Workbench from "../../../../cms/ui/themes/default/script/openrat/workbench.js"; 3 4 5 export default function(element ) { 6 7 // Wrapper Checkboxes will control the "hidden checkbox". 8 // So unchecked checkboxes will posted too. 9 $(element).find('.or-form-checkbox').change(function(e) { 10 this.nextElementSibling.value = this.checked ? '1' : '0'; 11 }); 12 13 // Restore the remembered check flag 14 $(element).find('.or-form-checkbox.or-remember').each( function() { 15 let key = 'preset.'+Workbench.state.action+'.'+this.dataset['name']; 16 if ( window.localStorage ) 17 this.checked = !!localStorage.getItem(key); 18 this.nextElementSibling.value = this.checked ? '1' : '0'; 19 }); 20 21 // Store the check flag 22 $(element).find('.or-form-checkbox.or-remember').change(function() { 23 let key = 'preset.'+Workbench.state.action+'.'+this.dataset['name']; 24 if ( window.localStorage ) 25 window.localStorage.setItem(key,this.checked?'1':''); 26 }); 27 28 }; 29 30
Download modules/template_engine/components/html/component_checkbox/checkbox.js
History Thu, 10 Mar 2022 13:09:06 +0100 dankert New: Remember some user inputs in the browser local storage. Wed, 9 Mar 2022 13:28:52 +0100 dankert Refactoring: Checkbox values are always sent to the server. In the actions we must test the value with 'isTrue()'