Вы можете переключать требуемое значение свойства из своего кода jQuery.
Я предполагаю, что атрибут data-comment
имеет тип boolean, и он всегда установлен, поэтому ваш оператор переключения может выглядеть следующим образом:
$('.information')
.on("change", ".record_to_information_form_information", function (event) {
event.preventDefault();
var $commentState = $(this).find('option:selected').data('comment');
//Test: to know if i received the attribute
console.log($commentState);
$('.comment').prop('required', $commentState);
});
Если вам нужно сделать что-то еще в вашем операторе if-else, вы можете просто оставить свое условие, указанное в примере:
if ($commentState === false) {
//the field isn't required
$('.comment').prop('required', false);
} else {
//the field is required
$('.comment').prop('required', true);
}