Custom Validation on Inline Edit.

Hello everyone,

I know this question have been asked couple of time but I cant find one that work now. All the topic are from 2015/2017.

I’ve done some custom validation in the edit view that work well. By adding a new custom JS file and alert user if it not fit my need. But now I also need to validate the data that are update in detail view with inline edit.

I’ve tried to add & edit "editablelistbutton.js " in /custom/modules/module name/clients/base/fields/editablelistbutton/editablelistbutton.js

I saw that in a lot of topic :

Repaire & rebuild but it does nothing, I thing this old file does not even exist now.

The only file about inline edit is here : /SuiteCRM/include/InlineEditing/inlineEditing.js

How can I customize it ? Just want to add some JS before save to fit my validation, like a phone number validation by regex for exemple.

Check here:

Hey @AlxGr,

Thanks for your answer. I’ve already saw (and commented lol) this topic, but its not update-friendly… I need something that will work with every update…

Still searching, Actually trying to load a custom js file in account module.

In this custom JS file im hooking doubleblick event, and trying to inject some code this way … Its not working for now.

Just found in my fav this video :

Its look like its fired in BOTH editview and inline edit ! That would be super nice if it work. I will try in more detail tomorrow.

Cool. Please let me know if it works.

Other approach will be to modify core files the way pgr recommends at the last post of this topic:

Thanks for the link, didnt know this one. The issue is that on every update I will have things to change… I already got a lot of code to change, I want to stop here, for know I have to take 1h on every update to replace everything… So I need to take an update friendly method for this …

Idk If I’ll find one, that bad cause I thing a lot of people need some custom validation on form.

The issue with the before save hook is that its in PHP not java … So its really harder to output alert etc.

Update : I’v tryed almost everything… Cant find something that work.

Now Im trying to do it by myself with a custom JS file, trigger a function on db click. The last thing that dont work is to stop execution of inlineEditing.js

He’s saving the field and im trying to stop this and take the focus of the current field. Will update this topic if I find a way !

After hours of re-search I find 1 one to do it.

In a custom js file I’ve put some code to detect inline edit :

	if ($(this).children().hasClass('inlineEditActive'))
		var ElementCourrant = $(this).children('div').eq(1);
		var ValueElement = (ElementCourrant).children('form').find('input').attr( "value" );


		//Touche entrée  -> voir inlineEditSaveButton !
			if (e.which == 13 && !e.shiftKey) 
				var TelPrincipale = $('#phone_office').val();

			   //Téléphone Principale
			   var RegexTelephone = /^(0)[1234567789]([\s]\d{2}){4}$/;
			   if(TelPrincipale != "") //Si pas vide
					if(RegexTelephone.test(TelPrincipale)) //Si tel pas vide -> on check 
						//Tous ok -> save
						$('#phone_office').css("background", "red");
						alert("Le téléphone principale n'est pas valide. Format attendus : 0X XX XX XX XX. N'oubliez pas les espaces !");

With only this code you will be able to alert the user about the error, but the original code will be performed, so the error will be saved in the data base.

To counter that I’ve created a before_save hook :

//Téléphone principale
		if(preg_match("/^(0)[1234567789]([\s]\d{2}){4}$/", $bean->phone_office)) 
			// phone is valid
			throw new Exception("Le téléphone principale n'est pas valide. Format attendus : 0X XX XX XX XX. N'oubliez pas les espaces !");

With this code, the error is not saved, It will keep the old value in the database.

The bad thing is that the validation is performed 2 times, in java and in php…

Would love to have some pro’s feedback on this. (@PGR ?)

1 Like

When it comes to Javascript, I am not a pro at all :slight_smile:

But if it works… I think it’s good enough…

1 Like

Thanks for the feedback, will stay with that double verification if its the only way.

If someone got a better/optimized version please send it over !