Commit d7a90aa9 authored by Florian Azizian's avatar Florian Azizian

FEAT #11270 TIME 0:30 check if custom field already exists in front

parent bba6b892
...@@ -65,7 +65,7 @@ class CustomFieldController ...@@ -65,7 +65,7 @@ class CustomFieldController
$id = CustomFieldModel::create([ $id = CustomFieldModel::create([
'label' => $body['label'], 'label' => $body['label'],
'type' => $body['type'], 'type' => $body['type'],
'values' => empty($body['values']) ? null : json_encode($body['values']), 'values' => empty($body['values']) ? '[]' : json_encode($body['values']),
'default_value' => $body['default_value'] 'default_value' => $body['default_value']
]); ]);
...@@ -99,7 +99,7 @@ class CustomFieldController ...@@ -99,7 +99,7 @@ class CustomFieldController
CustomFieldModel::update([ CustomFieldModel::update([
'set' => [ 'set' => [
'label' => $body['label'], 'label' => $body['label'],
'values' => empty($body['values']) ? null : json_encode($body['values']), 'values' => empty($body['values']) ? '[]' : json_encode($body['values']),
'default_value' => $body['default_value'] 'default_value' => $body['default_value']
], ],
'where' => ['id = ?'], 'where' => ['id = ?'],
......
...@@ -170,6 +170,12 @@ export class CustomFieldsAdministrationComponent implements OnInit { ...@@ -170,6 +170,12 @@ export class CustomFieldsAdministrationComponent implements OnInit {
customFieldToUpdate.values = customField.values.map((data: any) => data.label) customFieldToUpdate.values = customField.values.map((data: any) => data.label)
} }
const alreadyExists = this.customFields.filter(customField => customField.label == customFieldToUpdate.label );
if (alreadyExists.length > 1) {
this.notify.handleErrors(this.lang.customFieldAlreadyExists);
return of(false);
}
this.http.put('../../rest/customFields/' + customField.id, customFieldToUpdate).pipe( this.http.put('../../rest/customFields/' + customField.id, customFieldToUpdate).pipe(
tap(() => { tap(() => {
this.notify.success(this.lang.customFieldUpdated); this.notify.success(this.lang.customFieldUpdated);
......
...@@ -1081,4 +1081,5 @@ export const LANG_EN = { ...@@ -1081,4 +1081,5 @@ export const LANG_EN = {
"dateInput" : "Date input", "dateInput" : "Date input",
"radioInput" : "Radio input", "radioInput" : "Radio input",
"checkboxInput" : "Checbox input", "checkboxInput" : "Checbox input",
"customFieldAlreadyExists" : "Custom fields already exists with this name"
}; };
...@@ -1118,4 +1118,5 @@ export const LANG_FR = { ...@@ -1118,4 +1118,5 @@ export const LANG_FR = {
"dateInput" : "Champ date", "dateInput" : "Champ date",
"radioInput" : "Liste à choix unique", "radioInput" : "Liste à choix unique",
"checkboxInput" : "Liste à choix multiple", "checkboxInput" : "Liste à choix multiple",
"customFieldAlreadyExists" : "Un champ personnalisé existe déjà avec ce nom"
}; };
...@@ -1107,4 +1107,5 @@ export const LANG_NL = { ...@@ -1107,4 +1107,5 @@ export const LANG_NL = {
"dateInput" : "Date input", //_TO_TRANSLATE "dateInput" : "Date input", //_TO_TRANSLATE
"radioInput" : "Radio input", //_TO_TRANSLATE "radioInput" : "Radio input", //_TO_TRANSLATE
"checkboxInput" : "Checbox input", //_TO_TRANSLATE "checkboxInput" : "Checbox input", //_TO_TRANSLATE
"customFieldAlreadyExists" : "Custom fields already exists with this name" //_TO_TRANSLATE
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment