diff --git a/cypress/integration/control_rating.js b/cypress/integration/control_rating.js index b98e1d0845..15c11b352b 100644 --- a/cypress/integration/control_rating.js +++ b/cypress/integration/control_rating.js @@ -20,12 +20,13 @@ context('Control Rating', () => { cy.get('div.rating') .children('svg') + .find('.right-half') .first() .click() .should('have.class', 'star-click'); cy.get('@dialog').then(dialog => { var value = dialog.get_value('rate'); - expect(value).to.equal(1); + expect(value).to.equal(1/7); dialog.hide(); }); }); @@ -35,6 +36,7 @@ context('Control Rating', () => { cy.get('div.rating') .children('svg') + .find('.right-half') .first() .invoke('trigger', 'mouseenter') .should('have.class', 'star-hover') diff --git a/frappe/public/js/frappe/form/controls/rating.js b/frappe/public/js/frappe/form/controls/rating.js index cd10d2e62d..981168457a 100644 --- a/frappe/public/js/frappe/form/controls/rating.js +++ b/frappe/public/js/frappe/form/controls/rating.js @@ -73,14 +73,12 @@ frappe.ui.form.ControlRating = class ControlRating extends frappe.ui.form.Contro let out_of_ratings = this.df.options || 5; value = value * out_of_ratings; let el = $(this.input_area).find('svg'); - let is_half = value % 1 == 0.5; el.children('svg').prevObject.each( function(e) { if (e < value) { $(this).find('.left-half, .right-half').addClass('star-click'); - if (e == Math.floor(value) && is_half) { - $(this).find('.left-half').addClass('star-click'); - $(this).find('.right-half').removeClass('star-click'); - } + + let is_half = e == Math.floor(value) && value % 1 == 0.5; + is_half && $(this).find('.right-half').removeClass('star-click'); } else { $(this).find('.left-half, .right-half').removeClass('star-click'); }