[9.0] [WIP] website_crm_privacy_policy module migrate - #302
Conversation
1ecc11c to
0d68c36
Compare
| if (typeof jQuery === 'undefined') { throw new Error('Website CRM privacy policy addon requires jQuery') } | ||
| var core = require('web.core'); | ||
| var ajax = require('web.ajax'); | ||
| var _t = core._t; |
There was a problem hiding this comment.
Add var animation = require('web_editor.snippets.animation');
|
|
||
| +function ($) { | ||
| 'use strict'; | ||
| crm_policy.registry.accept_policy = snippet_animation.Class.extend({ |
There was a problem hiding this comment.
return animation.registry.accept_policy = animation.Class.extend({
| $(document).ready(function() { | ||
| var _t = openerp._t; | ||
| start: function() { | ||
| var self = this; |
| var _t = openerp._t; | ||
| start: function() { | ||
| var self = this; | ||
| this.$target.find('.o_website_form_send').on('click', function (e) { |
There was a problem hiding this comment.
Better get used to proxies: this.$('.o_website_form_send').on('click', $.proxy(this.accept_policy, this));
| $('form[action="/crm/contactus"]').on('submit', function(e) { | ||
| // Validate privacy_policy is checked | ||
| if(!$('input[name="privacy_policy"]').is(':checked')) { | ||
| accept_policy: function(e) { |
There was a problem hiding this comment.
Other developers appreciate real names for variables, functions, etc. Use event instead of e for the sake of readability please.
| e.preventDefault(); // Prevent the default submit behavior | ||
| this.$target.find('.o_website_form_send').off(); // Prevent users from crazy clicking | ||
|
|
||
| var self = this; |
There was a problem hiding this comment.
Remove this line, you are not using it.
4ff63e8 to
0c23225
Compare
| e.preventDefault(); // Prevent the default submit behavior | ||
| accept_policy: function(event) { | ||
| event.preventDefault(); // Prevent the default submit behavior | ||
| this.$target.find('.o_website_form_send').off(); // Prevent users from crazy clicking |
There was a problem hiding this comment.
The normal thing to do here is to disable the button instead of unbinding its events. Please make sure off() is doing what you expect.
| var self = this; | ||
| if(!this.target.find('input[name="privacy_policy"]').is(':checked')) { | ||
| e.preventDefault(); // Prevent form from submitting | ||
| if(!this.$target.find('input[name="privacy_policy"]').is(':checked')) { |
There was a problem hiding this comment.
You can use the this.$('input[name="privacy_policy"]') shorthand available in animations.
| crm_policy.registry.accept_policy = snippet_animation.Class.extend({ | ||
|
|
||
| return animation.registry.accept_policy = animation.Class.extend({ | ||
| selector: '.s_website_form', |
There was a problem hiding this comment.
You are affecting more forms than just the website_crm one, right? Shouldn't this be reflected in the addon name?
There was a problem hiding this comment.
How can affect "only" the website_crm form?
| @@ -9,28 +9,24 @@ odoo.define('website_crm_privacy_policy.crm_policy', function (require) { | |||
| var core = require('web.core'); | |||
| var ajax = require('web.ajax'); | |||
There was a problem hiding this comment.
I think you are not using this dependency. Please check and drop it if so.
There was a problem hiding this comment.
I have tested in runbot and current behavior is plainly broken. Alert triggers twice and form is never sent.
However, I checked that nowadays every major browser supports HTML5 validation, so how about simply removing all the JS stuff and replacing it by a required="required" attribute in the legal terms checkbox? That will trigger the native, beautiful and automatic browser validation with no extra work.
|
@yajo, please make the change as you have proposed. |
|
I just did a quick update, so you can see the idea, but did not test it. Let's wait for runbot and see. |
b732f62 to
4dee297
Compare
|
OK @pedrobaeza @cubells, this is interesting. With 4dee297 it works now. The problem is not about using or not HTML5 validation, the problem is that the new I decided to write the long explanation of the problem as a bug in odoo/odoo#14942, to keep it as a reference. Please check it out. |
pedrobaeza
left a comment
There was a problem hiding this comment.
Well, there's no visual sign that you lack of clicking on the accept terms, only "Invalid form". Can this be due to a missing class? For now, I'm merging, and if it can be improved, we make another PR.
… test fails on this dead link.
New `website_form` addon includes an undocumented validation system. By simply adapting layout to what it wants, we get validation for free.
4dee297 to
542c37f
Compare
|
I wait for merging until the question is solved. |
|
Yep, that's all explained in odoo/odoo#14942. The contactus form uses the Avoiding the BTW, doesn't the label get red when you don't check it? |
|
No, it doesn't. You don't have any visual sign of what is incorrect, which is very anti-user friendly. |
|
Sorry to correct you but it does: It gets red, and the field has an *. This is the expected behavior for a website_form-based form. I agree it's a 💩, but that must be fixed in odoo/odoo#14942 😞 |
|
OK, it's very weird indeed and I didn't even noticed about the text turning into red (I was expecting the checkbox is surrounded by red). Anyway, if there's no other solution, let's go this way. |


WIP
cc @Tecnativa