A
A
Alexey2016-11-22 12:11:30
JavaScript
Alexey, 2016-11-22 12:11:30

How to interrupt form submission in bitrix?

Good afternoon!
I can’t figure out how to stop submitting the form to Bitrix, this method doesn’t work:

var formID = "form_" + "<?=CUtil::JSEscape($arResult['FORM_ID'])?>";
var form = BX(formID);
var sourceEl = BX.findChild(form, { "tag":"select", "attr": { "name": "SOURCE_ID" } }, true, false);

BX.bind(form, 'submit', function(){
    var id = sourceEl.value;
    if(id == 20){
       alert(id);
       return false;
    }
});

alert fires but the submit is still in progress, how can I prevent the form from submitting?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Tsimur_S, 2016-11-22
@MrSen

have you tried that?
BX.bind(form, 'submit', function(event){
var id = sourceEl.value;
if(id == 20){
event.preventDefault() ;
event.stopPropagation();
alert(id);
}
}) ;

A
Alexander Korotaev, 2016-11-22
@lekzd

If it’s not so easy to get into the form code, then it’s easier to set disabled for an option that does not need to be selected, you can also hang custom validation on this select and if the form is sent via submit, then the sending will not be completed

M
Maxim Grechushnikov, 2016-11-22
@maxyc_webber

and what's stopping you from sending via jikveri or vanillage

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question