How add ajax after update

Hi,

On the OnScriptInit event I added this code :

<script>
$(document).ready(function() { 
	$('span[id^="id_read_on_id_fiche_"]').each(function () {		
		var value = $(this).text();
		$(this).html("<a href='../formulaire_usagers/index.php?id="+value+"' target='_parent' title='Consultez cette fiche'>"+value+"</a>");
		if (value == 0) $(this).html('');
	});
	
	$('span[id^="id_read_on_courriel_"]').each(function () {		
		var value = $(this).text();
		$(this).html("<a href=mailto:"+value+"' title='Envoyer un courriel'>"+value+"</a>");
	});
	
});
</script>

To get this result :

Unfortunately when I edit a line and save or cancel I don’t know how to apply this JavaScript code

Do you have an idea ?

Thank you

In a form app SC offers the possibility to define javascript functions.
Put your javascript code in a function F
Then use SC macro sc_ajax_function to call F in OnAfterUpdate event.

That being said I think there is a better way to accomplish what you need without worrying about javascript.
I would add a new label field in the form and use OnRecord event to set the field value to a mailto url.

1 Like

Hi
You are right about the macro, on the other hand I tried with OnUpdate, OnRefresh, nothing works. Maybe because I use a multiple (editable) form?

thank you

Put an echo in the php code of the event to check if the event fires properly

Hi Maxi,

Here is the type of form used :

If I add : echo “test”; in event “OnAfterUpdate” Nothing is happening

Thanks

Yannick,
clearly there is something wrong in your app.
In EditableGridView (or whatever is called in french) the event OnAfterUpdate must fires as soon as you update a record.
If you put an echo “TEST” in the first line of OnAfterUpdate, it must display TEST as soon as you click the update icon of the row.

My suggestion is to create another EditableGridView form, using the same SQL table, and start customizing it step by step always checking that after each step the event OnAfterUpdate fires correctly.

If it does not fire even at the very first step, just after the default code generation, there must be something in your DB that prevents the update transaction to complete.
Do you get the message "record updated succesfully " after the update ?
Can you enable debug info and see the message you get ?

Hi maxi,

Finally I added this line :slight_smile:

sc_ajax_javascript('linkidfiche');

in onScriptInit and everything works!

Thanks for your advice.

yammick:

could you explain how your solution works… i am having a similar issue, in this case what is “linkindfiche”?
is just the name of your script case form? or the name of your javascript fuction?

Hi Ferlash,

Yes, it is the name of my javascript function.

This is my new function :

$(document).ready(function() { 
	$('span[id^="id_read_on_id_fiche_"]').each(function () {		
		var value = $(this).text();
		//$(this).html("<a href='../formulaire_usagers/index.php?id="+value+"' class='url' target='_parent' title='Consultez cette fiche'>"+value+"</a>");
		$(this).html("<a href=\"javascript:nm_gp_submit('../formulaire_usagers/','id*scin"+value+"','','_parent','0','0','formulaire_usagers')\" class='url' title='Consultez cette fiche'>"+value+"</a>");
		if (value == 0) $(this).html('');
	});
	
	$('span[id^="id_read_on_courriel_"]').each(function () {		
		var value = $(this).text();
		$(this).html("<a href=mailto:"+value+" class='url' title='Envoyer un courriel'>"+value+"</a>");
	});
	
});

But I have yes error with this function php : avascript:nm_gp_submit() with parameters
Voila