first push message
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="survey_question_form_view_inherit" model="ir.ui.view">
|
||||
<field name="name">survey.question.form.inherit.answer_limit</field>
|
||||
<field name="model">survey.question</field>
|
||||
<field name="inherit_id" ref="survey.survey_question_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<!-- Insert after suggested answers section for multiple_choice -->
|
||||
<xpath expr="//field[@name='suggested_answer_ids']/../.." position="after">
|
||||
<group
|
||||
string="Answer Limits" invisible="question_type != 'multiple_choice'"
|
||||
colspan="2"
|
||||
>
|
||||
<field name="validation_multiple_answers_min" required="validation_multiple_answers_max != False"/>
|
||||
<field name="validation_multiple_answers_max"/>
|
||||
<field name="validation_error_msg" colspan="2"
|
||||
required="validation_multiple_answers_max != False"/>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<template id="survey_answer_limit_assets" inherit_id="survey.survey_page">
|
||||
<xpath expr="//head" position="inside">
|
||||
<script type="text/javascript">
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
console.log('🔍 Survey validation script loaded');
|
||||
|
||||
// Find all multiple choice questions with max_answers
|
||||
const questionContainers = document.querySelectorAll('.o_survey_question');
|
||||
|
||||
questionContainers.forEach(container => {
|
||||
// Look for max_answers in data attribute or hidden field
|
||||
const maxAnswersEl = container.querySelector('[data-max-answers]');
|
||||
const maxAnswers = maxAnswersEl ? parseInt(maxAnswersEl.dataset.maxAnswers) : 0;
|
||||
|
||||
if (!maxAnswers) return;
|
||||
|
||||
console.log('✅ Found question with max_answers:', maxAnswers);
|
||||
|
||||
const checkboxes = container.querySelectorAll('input[type="checkbox"]');
|
||||
const questionId = container.dataset.questionId || 'unknown';
|
||||
|
||||
// Add visual hint
|
||||
const hint = document.createElement('small');
|
||||
hint.className = 'text-muted d-block mt-2';
|
||||
hint.textContent = `(សូមជ្រើសរើសត្រឹមតែ ${maxAnswers} ជម្រើសប៉ុណ្ណោះ)`;
|
||||
const answersContainer = container.querySelector('.o_survey_question_answers');
|
||||
if (answersContainer) {
|
||||
answersContainer.appendChild(hint);
|
||||
}
|
||||
|
||||
// Checkbox change handler
|
||||
checkboxes.forEach(checkbox => {
|
||||
checkbox.addEventListener('change', function() {
|
||||
const checked = container.querySelectorAll('input[type="checkbox"]:checked');
|
||||
|
||||
if (checked.length > maxAnswers) {
|
||||
this.checked = false;
|
||||
alert(`⚠️ ចំនួនជម្រើសលើសពីកំណត់!\nសូមជ្រើសរើសត្រឹមតែ ${maxAnswers} ជម្រើសប៉ុណ្ណោះ។`);
|
||||
}
|
||||
|
||||
// Disable unchecked when limit reached
|
||||
checkboxes.forEach(cb => {
|
||||
if (!cb.checked) {
|
||||
cb.disabled = (checked.length >= maxAnswers);
|
||||
} else {
|
||||
cb.disabled = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Submit/Next button validation
|
||||
const submitBtn = container.closest('form').querySelector('button[type="submit"][value="next"], #next_page, .btn-primary');
|
||||
if (submitBtn) {
|
||||
submitBtn.addEventListener('click', function(e) {
|
||||
const checked = container.querySelectorAll('input[type="checkbox"]:checked');
|
||||
|
||||
if (checked.length > maxAnswers) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
alert(`❌ ការជ្រើសរើសរបស់អ្នកលើសពីកំណត់!\nសូមជ្រើសរើសត្រឹមតែ ${maxAnswers} ជម្រើសប៉ុណ្ណោះ。\n\nចំនួនដែលបានជ្រើសរើស: ${checked.length}`);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user