Welcome, Guest
Username: Password: Remember me

TOPIC: Adding javascript to save function

Adding javascript to save function 02 May 2012 18:05 #2221

  • jroberge
  • jroberge's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
Hello,

I would like to add a call to the save function. I am looking for a way to close a modal window once the save button is clicked. I have tried adding window.parent.SqueezeBox.close();:
Joomla.submitbutton = function(pressbutton)
{
document.formvalidator.submitform(document.adminForm, pressbutton, function(pressbutton){
window.parent.SqueezeBox.close();
return Joomla.submitform(pressbutton);
});
return false;
}

The line window.parent.SqueezeBox.close(); doesn't seem to be executed. Why? Is there another way to add javascript to particular views?

Thanks,
The administrator has disabled public write access.

Re: Adding javascript to save function 07 May 2012 19:07 #2262

  • jroberge
  • jroberge's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
Hmmm, no answer... Does it mean it is impossible to add a javascript call to the buttons (be it Save, Apply or Cancel)? How can one add a confirm button to those buttons?

Thanks,
The administrator has disabled public write access.

Re: Adding javascript to save function 07 May 2012 19:30 #2263

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Hi jroberge,

Excuse me for beiing long.

In facts ... hum I will answer you soon.

I am now ugrading the service.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Adding javascript to save function 07 May 2012 20:29 #2272

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Hum, maybe because it is not called ;-)
try to alert() inside...



Did you knew this one :

BACK com_xxxxx/js/formvalidator.js
/*
*	FORMVALIDATOR - OPTIMIZATION OF THE JOOMLA NATIVE CLASS
*
*
*	-> New functions to handle the test
*	-> Pass the element object in the handler function (and much more arguments in the triggers)
*	-> Triggers before and after test
*	-> Messages boxes next to the fields
*	-> Global error message customizable
*	-> Handle radio and checkboxes
*	-> Handle editor
*
*	-> Nothing deprecated, all natives functionalities are still present
*
*
*	TO ADD A TRIGGER :
*
*
*	/**
*	* Functions to add a trigger
*	*
*	* @arg output object (described as below)
*	*
*	* @args.value 				: the tested value. You can transform the value before the test. This value will not be rewrited inside the input.
*	* @args.regex 				: the regexp
*	* @args.element		 		: input element. Use this if you want rewrite inside the input, or what you want...
*	* @args.name 				: field name
*	* @args.valid 				: result of the validation. Override here the result of a your custom test before of after
*	* @args.msgInfo				: the information message
*	* @args.msgIncorrect 		: the incorrect message
*	* @args.msgRequired 		: the required message
*	* @args.displayInfo 		: Displays the info box
*	* @args.displayIncorrect 	: Displays the incorrect box
*	* @args.displayRequired 	: Displays the required box
*	*
*	* @args.message 			: the message to show in alert box when submit (include field name. You can use <%LABEL%> pattern)*
*	*
*	**
*
*
*	onBeforeValidation['my_handle'] = function(args)	// my_handle : ie : email, username, password, ...
*	onAfterValidation['my_handle'] = function(args)
*	onBeforeValidation['required'] = function(args)		// For 'required' check  (Before)
*	onAfterValidation['required'] = function(args)		// For 'required' check  (After)
*	{
*	}
*
*
*	/**
*	* Functions to add a trigger
*	*
*	* @arg output object (described as below)
*	*
*	* @args.doit 				: Show the alert box (args.doit = false to disable the 'invasive' alert box)
*	* @args.message 			:  Formated message, (for instance, you can add a title)
*	*
*	**
*	
*	onBeforeValidationAlert = function(args)
*	{
*	}
*
*/


Line 492 :
document.formvalidator.submitform = function(form, pressbutton, callback)
{

	...
}
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Adding javascript to save function 08 May 2012 09:23 #2280

  • jroberge
  • jroberge's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
Yes, it is not being called from the form and I am wondering why. If I add an alert() to the com_xxxxx/js/formvalidator.js file, it does appear. But I what I would like to do is to add it in my form, in the view that produces the form. Maybe I don't understand the role of the javascript section at the top of my file:
<?php Suivirm6Helper::headerDeclarations(); ?>

<h1 class='componentheading'><?php echo(JText::_("SUIVIRM6_LAYOUT_NOUVEAU_SUIVI"));?></h1>

<script language="javascript" type="text/javascript">
	Joomla.submitbutton = function(pressbutton)
	{
		document.formvalidator.submitform(document.adminForm, pressbutton, function(pressbutton){
			alert('On est dans la fonction document.formvalidator.submitform de nouveausuivi');
			return Joomla.submitform(pressbutton);
		});
	   	return false;
	}
</script>

<form action="<?php echo(JRoute::_("index.php")); ?>" method="post" name="adminForm" id="adminForm" class='form-validate'>
	<div>
		<?php echo JDom::_('html.toolbar', array(
			"bar" => $this->lists['toolbar']
			));
		?>
		<?php echo $this->loadTemplate('fly'); ?>
		<?php echo $this->loadTemplate('form'); ?>
	</div>

	<?php echo JDom::_('html.form.footer', array(
		'dataObject' => $this->suivisitem,
		'values' => array(
				'option' => "com_suivirm6",
				'view' => "suivisitem",
				'layout' => "nouveausuivi"
				)));
	?>
</form>

If I remove the javascript part ...
<script language="javascript" type="text/javascript">
	Joomla.submitbutton = function(pressbutton)
	{
		document.formvalidator.submitform(document.adminForm, pressbutton, function(pressbutton){
			alert('On est dans la fonction document.formvalidator.submitform de nouveausuivi');
			return Joomla.submitform(pressbutton);
		});
	   	return false;
	}
</script>

... the behavior of the form is not modified.
  1. the alert I placed in formvalidator.js is called
  2. the message " is requested. Please retry. Erreur" is posted and the form is not processed
  3. the user is sent back to the form

Why is that? What is the use of that "javascript" section?

Thanks again,
The administrator has disabled public write access.

Re: Adding javascript to save function 09 May 2012 16:18 #2294

  • jroberge
  • jroberge's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
I just realize that this behavior is only seen on the public forms. It reacts as expected in the forms residing on the admin side.
The administrator has disabled public write access.

Re: Adding javascript to save function 16 May 2012 10:10 #2370

  • jroberge
  • jroberge's Avatar
  • Offline
  • Junior Member
  • Posts: 23
  • Karma: 0
Am I the only one having such a problem?

Thanks
The administrator has disabled public write access.

Re: Adding javascript to save function 12 Nov 2012 12:10 #5305

I am having the same problem.

I have two forms available on my website that users can enter data on. The first one is a form containing many fileds, most of them are mandatory. On the second form I use fewer fields. The second form is where the errors are generated.

I think that it has to do with form two saving "incomplete data". The system thinks that because a field is set to mandatory in admin that it must be present when saving data from the front end even if that field is not in use on that form.

How can we prevent the error?
The administrator has disabled public write access.

Re: Adding javascript to save function 12 Nov 2012 12:51 #5306

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @visibility,

Please see this thread here: j-cook.pro/forum/9-coding-inside-your-co...ds-in-front-end-form that describes how to show, hide and disable fields on a form using jQuery. It also includes all the code you need to achieve it.

You'll need to read it all but the part that you need specifically is: j-cook.pro/forum/9-coding-inside-your-co...-front-end-form#4490 that will remove the required class on fields that you want to ignore programmatically.

Hope it helps!

Best wishes,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Adding javascript to save function 12 Nov 2012 22:22 #5307

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @visibility,

Did you get it working?

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.
Time to create page: 0.158 seconds

Get Started