From 1b0a0fe14fd13ec5815f2bae852bf9544ff406af Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 9 Jul 2021 11:56:53 +0200 Subject: [PATCH] Improve reset button in forms --- www/form/inner.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/www/form/inner.js b/www/form/inner.js index a1c7f4c93..c49910411 100644 --- a/www/form/inner.js +++ b/www/form/inner.js @@ -1492,11 +1492,11 @@ define([ els ]); var $tag = $(tag); - var reorder = function () { + var reorder = function (reset) { $tag.find('.cp-form-type-sort').each(function (i, el) { - $(el).find('.cp-form-sort-order').text(i+1); + $(el).find('.cp-form-sort-order').text(reset ? '?' : i+1); }); - sorted = true; + sorted = !reset; }; var cursorGetter; var setCursorGetter = function (f) { cursorGetter = f; }; @@ -1525,11 +1525,12 @@ define([ }); }, reset: function () { + Util.shuffleArray(opts.values); var toSort = (opts.values).map(function (val) { return invMap[val]; }); sortable.sort(toSort); - reorder(); + reorder(true); }, edit: function (cb, tmp) { var v = Util.clone(opts); @@ -1889,12 +1890,13 @@ define([ } var send = h('button.cp-open.btn.btn-primary', update ? Messages.form_update : Messages.form_submit); - var reset = h('button.cp-open.btn.btn-danger-alt', Messages.form_reset); + var reset = h('button.cp-open.cp-reset-button.btn.btn-danger-alt', Messages.form_reset); $(reset).click(function () { if (!Array.isArray(APP.formBlocks)) { return; } APP.formBlocks.forEach(function (data) { if (typeof(data.reset) === "function") { data.reset(); } }); + $(reset).attr('disabled', 'disabled'); }); var $send = $(send).click(function () { $send.attr('disabled', 'disabled'); @@ -2008,6 +2010,7 @@ define([ delete _answers._userdata; evOnChange.reg(function (noBeforeUnload, isSave) { if (noBeforeUnload) { return; } + $container.find('.cp-reset-button').removeAttr('disabled'); var results = getFormResults(); if (isSave) { answers = Util.clone(results || {}); @@ -2360,6 +2363,9 @@ define([ // In view mode, add "Submit" and "reset" buttons $container.append(makeFormControls(framework, content, Boolean(answers), evOnChange)); + if (!answers) { + $container.find('.cp-reset-button').attr('disabled', 'disabled'); + } }; var getTempFields = function () {