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
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.
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 !
In a custom js file I’ve put some code to detect inline edit :
$('div.detail-view-row-item').dblclick(function(e)
{
if ($(this).children().hasClass('inlineEditActive'))
{
var ElementCourrant = $(this).children('div').eq(1);
var ValueElement = (ElementCourrant).children('form').find('input').attr( "value" );
$(ElementCourrant).css('white-space','inherit');
//Touche entrée -> voir inlineEditSaveButton !
$(document).keypress(function(e)
{
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
}
else
{
$(ElementCourrant).removeClass('inlineEditActive');
$('#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 !");
$('#phone_office').focus();
}
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
}
else
{
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 ?)