[FIX] website, website_hr_recruitment: give the priority to auto-fill

This commit allows to give priority to auto-fill values and to values
coming from a data-for when in addition to one of these values this same
field has a default value. The form's test are also improved so that it
checks for this desired behavior.

task-2715201

X-original-commit: 7b23d3aacd22f87cb0c22ecd0478eba4a17b4bf3
Part-of: odoo/odoo#90103
This commit is contained in:
Guillaume (gdi)
2022-04-29 13:13:10 +02:00
committed by qsm-odoo
parent 9c25421677
commit 8d0a63f355
3 changed files with 26 additions and 13 deletions
@@ -143,9 +143,9 @@ odoo.define('website.s_website_form', function (require) {
for (const name of fieldNames) {
const fieldEl = this.$target[0].querySelector(`[name="${name}"]`);
let newValue;
if (!fieldEl.value && dataForValues && dataForValues[name]) {
if (dataForValues && dataForValues[name]) {
newValue = dataForValues[name];
} else if (!fieldEl.value && this.preFillValues[fieldEl.dataset.fillWith]) {
} else if (this.preFillValues[fieldEl.dataset.fillWith]) {
newValue = this.preFillValues[fieldEl.dataset.fillWith];
}
if (newValue) {
@@ -300,7 +300,7 @@ odoo.define('website.tour.form_editor', function (require) {
trigger: '.s_website_form_send.btn.btn-sm.btn-secondary.rounded-circle',
run: () => null,
},
// Add a default value.
// Add a default value to a auto-fillable field.
{
content: 'Select the name field',
trigger: '.s_website_form_field:eq(0)',
@@ -309,20 +309,13 @@ odoo.define('website.tour.form_editor', function (require) {
trigger: 'we-input[data-attribute-name="value"] input',
run: 'text John Smith',
},
// Save the page
{
trigger: 'body',
run: function () {
$('body').append('<div id="completlyloaded"></div>');
},
},
{
content: "Save the page",
trigger: "button[data-action=save]",
},
{
content: "Wait reloading...",
trigger: "html:not(:has(#completlyloaded)) div",
content: 'Verify value attribute and property',
trigger: '.s_website_form_field:eq(0) input[value="John Smith"]:propValue("Mitchell Admin")',
},
// Check that if we edit again and save again the default value is not deleted.
{
@@ -74,6 +74,14 @@ odoo.define('website_hr_recruitment.tour', function(require) {
}, {
content: 'Enter in edit mode',
trigger: 'a[data-action="edit"]',
}, {
content: 'Add a fake default value for the job_id field',
trigger: 'button[data-action="save"]',
run: () => {
// It must be done in this way because the editor does not allow to
// put a default value on a field with type="hidden".
document.querySelector('input[name="job_id"]').value = 'FAKE_JOB_ID_DEFAULT_VAL';
},
}, {
content: 'Edit the form',
trigger: 'input[type="file"]',
@@ -100,11 +108,23 @@ odoo.define('website_hr_recruitment.tour', function(require) {
content: 'Check that a job_id has been loaded',
trigger: 'form',
run: () => {
const selector = 'input[name="job_id"]:not([value=""])';
const selector =
'input[name="job_id"]:not([value=""]):not([value = "FAKE_JOB_ID_DEFAULT_VAL"])';
if (!document.querySelector(selector)) {
console.error('The job_id field has a wrong value');
}
}
}, {
content: 'Enter in edit mode',
trigger: 'a[data-action="edit"]',
}, {
content: 'Verify that the job_id field has kept its default value',
trigger: 'button[data-action="save"]',
run: () => {
if (!document.querySelector('input[name="job_id"][value="FAKE_JOB_ID_DEFAULT_VAL"]')) {
console.error('The job_id field has lost its default value');
}
}
},
]);