How to prevent prompt dialog to close if not right value?

Im opening 2 dynamic prompts dialog and I want to prevent it to close when I click on the OK button if it is not valid.

The first one I want to check if it is only numbers and the second one I want to validate 2 input fields with a time value.
I get it to write the data-error-message text correctly if it is the wrong value, but even if it is validating and showing the correct error text it still closes if I write the wrong value.
So how do I prevent it from closing if it is not the right value? And not running the skickaregistrering() function.

The first one with only numbers.

        function franvarokoll(data){
        var dialog = app.dialog.create({
        	title: 'Frånvaro i minuter',
        	text: 'Write minutes, only numbers.',
        	content: '<div class="dialog-input-field item-input"><div class="item-input-wrap"><input class="dialog-input" type="tel" placeholder="Only numbers" required validate pattern="[0-9]*" data-error-message="Only numbers" ></div></div>',
        	buttons: [{text: 'OK'}],
        	onClick: function (dialog, index) {
        	console.log(dialog.$el.find('.dialog-input').val());
        	data3=dialog.$el.find('.dialog-input').val()
        	
        	skickaregistrering('Minutes','','',data3);
        	},
        	on: {
        	open: function () {
        	console.log("OPEN");
        	}
        	}
        	}).open();
        }

The second one with time values.

var dialog = app.dialog.create({
	title: 'Frånvaro tid',
	text: 'Skriv från vilken tid till vilken tid. Format xx:xx',
	content: '<div class="dialog-input-field item-input"><div class="item-input-wrap"><input class="dialog-input" type="time" placeholder="Från tid xx:xx" required validate pattern="[0-9][0-9]:[0-9][0-9]" data-error-message="Skriv format 00:00" style="margin-bottom:8px;"/><input class="dialog-input dialognr2" type="time" placeholder="Till tid xx:xx" required validate pattern="[0-9][0-9]:[0-9][0-9]" style="margin-bottom:8px;"/></div></div>',
	buttons: [{text: 'OK'}],
	onClick: function (dialog, index) {
	timenr1=dialog.$el.find('.dialog-input').val()
	timenr2=dialog.$el.find('.dialognr2').val()
	$$(dialog.$el.find('.dialog-input')).val().focus();
	
	skickaregistrering("Del av dag",timenr1,timenr2)
	},
	on: {
	open: function () {
	console.log("OPEN");
	}
	}
}).open();

Also how do I set the focus in the input?
I have tried with variations of this.
$$(dialog.$el.find('.dialog-input')).val().focus();

Thanks a lot for any input.

add close: false prop to dialog button and it won’t close automatically on click. Close it manually within onClick handler if it matches required conditions

1 Like

Ok, thanks a lot. Vladimir