You are viewing limited content. For full access, please sign in.

Question

Question

Stored procedure on submit

asked on January 11, 2017

I recently upgrade from forms v9.2 >> 10.1 and I'm getting some unexpected behavior on a form using a stored procedure that is called when the submit button is clicked.  I'm using some of the logic found [Here] but it requires users to click the submit button twice.  I'm no JS expert, so I'm not 100% sure what's going on.  See code examples below:

Current Code - This submits and everything works correctly, other than having to click the submit button twice.

  $('.action-btn').on('click', function(event)  
  {
    if ($('.notused input').val() == "") //This is the stored proc trigger
        {
          $('#q3 input').attr('readonly', 'true');//this is the claim number field I'm looking to fill with the stored procedure
          $('#q2 input').val("1").trigger('change');//This is the stored proc trigger
          event.preventDefault();
          waitfunction();
        }
  });
  function fieldfilled()
  {
    return ($('#q3 input').val() != '');
  }
  
  function waitfunction()
  {
    setTimeout(function(){    
      if(fieldfilled())
        console.log('nothing');
      else
        waitfunction();
    }, 500);
  }

Here is the code I was using before my upgrade that worked just fine!  Now it does not save the Claim number to my repository:

$('.action-btn').on('click', function()  
  {
    if ($('.notused input').val() == "") //stored proc trigger
    	{
			$('#q3 input').attr('readonly', 'true');//claim number
    		$('.notused input').val("1").trigger('change');
    	}
  });

 

1 0

Answer

SELECTED ANSWER
replied on January 12, 2017

Yeah you are right.

You can try change it to the following:

$(".Submit").click();
2 0

Replies

replied on January 11, 2017

Hi Nate,

1. For the "current code", it still requires clicking twice to submit, unless you change "console.log('nothing');" to "document.getElementById('form1').submit();" as the reference answers post;

2. For the code you used before upgrade, it does not wait for lookup value to be filled so the value is not submitted. I tried the "current code" and it worked in Forms 10.1

0 0
replied on January 11, 2017

Rui,

Thanks for the quick reply.  The downfall to the 'current code' is that it will let me submit without having the required fields completed if I add that code into the code block.  That is obviously not ideal.  Maybe I just need to tweak that?  Below is a link that shows the form submits even when fields are not filled.  

https://www.screencast.com/t/xIKK7kpTCsQt

0 0
SELECTED ANSWER
replied on January 12, 2017

Yeah you are right.

You can try change it to the following:

$(".Submit").click();
2 0
replied on January 13, 2017

That did it!  Thanks Rui!

0 0
replied on January 19, 2017

Rui,

Thanks again for your help above.  Now that this has been in testing for a bit, I have run into some behavior that was not expected from my users.  Basically, the user is loading the form, clicking submit without all the required fields filled (which generates a Claim Number), then exiting the form all together.  This causes the claim number to be 'skipped' and causes errors.  I'm looking for a way to validate that all required fields are filled before it will generate the claim number.. Here's what I have tried with no luck..

$('.action-btn').on('click', function(event)  
{
  if ($('.notused input').val() === "") //This is the stored proc trigger
      {
        $('.notused input').val("1").trigger('change');//This is the stored proc value to trigger the procedure
        event.preventDefault();
        waitfunction();
      }
});
function fieldfilled()
{
  return ($('.cf-required').val() !== '');
}

function waitfunction()
{
  setTimeout(function(){    
    if(fieldfilled())
      $('#form1').submit();
    else
      waitfunction();
  }, 500);
}

Thanks,

Nate

0 0
replied on January 20, 2017

Hi Nate,

If you do not want the stored proc to be triggered unless required fields are filled, you could try script like this:

$('.action-btn').on('click', function(event)  
{
  if (requiredfilled() && $('.notused input').val() === "") //This is the stored proc trigger
      {
        $('.notused input').val("1").trigger('change');//This is the stored proc value to trigger the procedure
        event.preventDefault();
        waitfunction();
      }
});
function requiredfilled()
{
  return _.every($('li:has(.cf-required) input,li:has(.cf-required) textarea'), function(elm) {return $(elm).val() != '';});
}
function fieldfilled()
{
  return ($('#q3 input').val() != '');
}

function waitfunction()
{
  setTimeout(function(){    
    if(fieldfilled())
      $(".Submit").click();
    else
      waitfunction();
  }, 500);
}

Please note that the above requiredfilled function only checkes input and textarea type field. If you need to check other kinds of fields, you need to update this function.

0 0
replied on January 20, 2017

Rui,

I tried this and the number did not generate.  I'm wondering if it has to do with me having required fields that are hidden as part of a 'Field Rule' - I wonder if the system interprets them as still being required?  Below is the code I have:

$('.action-btn').on('click', function(event)  
{
  if (requiredfilled() && $('.notused input').val() === "") //This is the stored proc trigger
      {
        $('.notused input').val("1").trigger('change');//This is the stored proc trigger
        event.preventDefault();
        waitfunction();
      }
});
  
function requiredfilled()
{
  return _.every($('li:has(.cf-required) input,li:has(.cf-required) textarea'), function(elm) {return $(elm).val() != '';});
}
function fieldfilled()
{
  return ($('.required input').val() !== '');
}

function waitfunction()
{
  setTimeout(function(){    
    if(fieldfilled())
      $('#form1').submit();
    else
      waitfunction();
  }, 500);
}

Nate

0 0
replied on January 21, 2017 Show version history

If you have hidden required field, you could change the function to

function requiredfilled()
{
  return _.every($('li:has(.cf-required):visible input,li:has(.cf-required):visible textarea'), function(elm) {return $(elm).val() != '';});
}

For hidden required fields, Forms would not treat them as required but previous script would still check them so the submit action did not get blocked.

The modified script would ignore those hidden required fields.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.