jquery-steps icon indicating copy to clipboard operation
jquery-steps copied to clipboard

Steps with Form Validation and Ajax request

Open ssolarz opened this issue 9 years ago • 6 comments

I have a form at www.lgbtcm.com that uses Steps and form validation. I can get the form validation to work with an Ajax call to verify if a username or email is working but then it disables the ability to move to the next Step.

bemail: { validators: { notEmpty: { message: 'The email address is required' }, emailAddress: { message: 'The input is not a valid email address' }, remote: { url: '<?php echo get_bloginfo('url'); ?>/wp-admin/admin-ajax.php', type: "GET", message: 'This email is already in use', cache: false, async: false } } },

How can I get the Steps to work with the form.?? THANKS!

ssolarz avatar Apr 03 '16 06:04 ssolarz

Same problem here... Please tell if you find a solution

zerowar avatar Apr 27 '16 12:04 zerowar

+1

jonathanGB avatar Aug 25 '16 04:08 jonathanGB

I have the same issue. The whole problem is that the onStepChanging function is supposed to return true or false. It is not designed to run an async code.

martinkrcho avatar Aug 22 '17 14:08 martinkrcho

+1

Nihar-Samineni avatar Aug 22 '17 14:08 Nihar-Samineni

//I was not worried, I just wrote:

var is_async_step = false;
$(document).ready(function ()
{
	var settings = {
		onStepChanging: ChangeStep
	};
	$("#wizard").steps(settings);
});

function ChangeStep(event, currentIndex, newIndex)
{
	if (is_async_step)
	{
		is_async_step = false;
		//Allow next step
		return true;
	}

	var arr = $("#form_tag_id").serializeArray();
	arr.push({ name: "one_more_field", value: "one_more_value" });
	$.post("", arr).done(function (data)
	{
		if(data != "ok")
		{
			return;
		}

		is_async_step = true;
		//trigger navigation event
		$("#wizard").steps("next");
	});

	//forbid the next step because $.post is an asynchronous function
	return false;
}

hedgehed avatar Jan 28 '18 11:01 hedgehed

@hedgehed Thank you for your solution, I had been sick of searching the internet and no good, Your approach is simple and crisp. Thank you buddy !

keshav1245 avatar Jun 03 '21 13:06 keshav1245