From a12603d14e1d6dc24fbb10e6d85822f101f0ba1d Mon Sep 17 00:00:00 2001 From: James Lucas Date: Tue, 10 Oct 2023 10:12:28 +1100 Subject: [PATCH 1/2] fix: starControl did not save nor load userData --- src/js/control_plugins/starRating.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/js/control_plugins/starRating.js b/src/js/control_plugins/starRating.js index 904ac34af..9281ed7ea 100644 --- a/src/js/control_plugins/starRating.js +++ b/src/js/control_plugins/starRating.js @@ -27,25 +27,32 @@ window.fbControls.push(function(controlClass) { * javascript & css to load */ configure() { - this.js = '//cdnjs.cloudflare.com/ajax/libs/rateYo/2.2.0/jquery.rateyo.min.js' - this.css = '//cdnjs.cloudflare.com/ajax/libs/rateYo/2.2.0/jquery.rateyo.min.css' + this.js = 'https://cdnjs.cloudflare.com/ajax/libs/rateYo/2.3.2/jquery.rateyo.min.js' + this.css = 'https://cdnjs.cloudflare.com/ajax/libs/rateYo/2.3.2/jquery.rateyo.min.css' } /** * build a text DOM element, supporting other jquery text form-control's - * @return {HTMLElement} DOM Element to be injected into the form. + * @return {HTMLElement|Object|HTMLElement[]} DOM Element to be injected into the form. */ build() { - this.dom = this.markup('span', null, { id: this.config.name }) - return this.dom + this.input = this.markup('input', null, { ...this.config, type: 'hidden', }) + this.field = this.markup('span') + return [this.input, this.field] } /** * onRender callback */ onRender() { - const value = this.config.value || 3.6 - $(this.dom).rateYo({ rating: value }) + const value = this.config.userData ? this.config.userData[0] : this.config.value || 3.6 + const input = $(this.input) + $(this.field).rateYo({ + rating: value, + onSet: function(rating) { + input.val(rating) + } + }) } } From f34a259bf82e24c670381872dcc85edb027c186a Mon Sep 17 00:00:00 2001 From: James Lucas Date: Tue, 10 Oct 2023 10:21:10 +1100 Subject: [PATCH 2/2] fix: update tests for starRating --- tests/control/control_plugin.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/control/control_plugin.test.js b/tests/control/control_plugin.test.js index af20adbf0..14a95dd80 100644 --- a/tests/control/control_plugin.test.js +++ b/tests/control/control_plugin.test.js @@ -27,8 +27,10 @@ describe('Test Custom Control', () => { expect(typeof controlInstance).toBe('object') expect(controlInstance.constructor.name).toBe('controlStarRating') - const element = controlInstance.build() - expect(element.constructor.name).toBe('HTMLSpanElement') + const controlBuild = controlInstance.build() + const element = controlBuild[0] + expect(element.constructor.name).toBe('HTMLInputElement') expect(element.id).toBe('star-1492424082853') + expect(element.type).toBe('hidden') }) }) \ No newline at end of file