fix textarea with select by adding a button (#30785)

Co-authored-by: Hystepik <lmarcouiller@nltechno.com>
This commit is contained in:
Lucas Marcouiller 2024-08-29 09:27:42 +02:00 committed by GitHub
parent 8bbe0516f4
commit 94b3566ddc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -7505,6 +7505,7 @@ abstract class CommonObject
// If the textarea field has a list of arrayofkeyval into its definition, we suggest a combo with possible values to fill the textarea.
//var_dump($param['options']);
$out .= $form->selectarray($keyprefix.$key.$keysuffix."_multiinput", $param['options'], '', 1, 0, 0, "flat maxwidthonphone".$morecss);
$out .= '<input id="'.$keyprefix.$key.$keysuffix.'_multiinputadd" type="button" class="button" value="'.$langs->trans("Add").'">';
$out .= "<script>";
$out .= '
function handlemultiinputdisabling(htmlname){
@ -7526,16 +7527,16 @@ abstract class CommonObject
}
$(document).ready(function () {
$("#'.$keyprefix.$key.$keysuffix.'_multiinput").on("change",function() {
$("#'.$keyprefix.$key.$keysuffix.'_multiinputadd").on("click",function() {
console.log("We add the selected value to the text area '.$keyprefix.$key.$keysuffix.'");
tmpval = $("#'.$keyprefix.$key.$keysuffix.'").val();
tmpvalarray = tmpval.split(",");
valtotest = $(this).val();
valtotest = $("#'.$keyprefix.$key.$keysuffix.'_multiinput").val();
if(valtotest != -1 && !tmpvalarray.includes(valtotest)){
if(tmpval == ""){
tmpval = valtotest;
} else {
tmpval = tmpval + "," + valtotest;
tmpval = tmpval + "\n" + valtotest;
}
$("#'.$keyprefix.$key.$keysuffix.'").val(tmpval);
handlemultiinputdisabling("'.$keyprefix.$key.$keysuffix.'");

View File

@ -472,7 +472,8 @@ class Target extends CommonObject
public function update(User $user, $notrigger = 0)
{
// Clean trigger_codes
$this->trigger_codes = preg_replace('/[\r\n\s]/', '', $this->trigger_codes);
$this->trigger_codes = preg_replace('/\r\n/', ',', $this->trigger_codes);
$this->trigger_codes = preg_replace('/\s/', '', $this->trigger_codes);
return $this->updateCommon($user, $notrigger);
}