Allow to store and retrieve combobox multivalues with commas

spring-update
George Kalampokis 3 years ago
parent add23dab2f
commit dcf88479bd

@ -17,6 +17,7 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -239,6 +240,18 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
} else if (this.value instanceof Collection) {
Collection valueCollection = (Collection) this.value;
StringBuilder valueBuilder = new StringBuilder();
valueBuilder.append("[");
for (int i = 0; i < valueCollection.size(); i++) {
valueBuilder.append(parseString(valueCollection.stream().toArray()[i]));
if (i < valueCollection.size() - 1) {
valueBuilder.append(", ");
}
}
valueBuilder.append("]");
fieldValues.put(this.id, valueBuilder.toString());
} else {
fieldValues.put(this.id, this.value.toString());
}
@ -251,4 +264,13 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin
public void toMap(Map<String, Object> fieldValues, int index) {
fieldValues.put(this.id, this.value);
}
private String parseString(Object value) {
if (value instanceof String) {
if (((String)value).contains(",")) {
return "\"" + value + "\"";
}
}
return value.toString();
}
}

@ -106,7 +106,9 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
if (this.form.get('data').value.multiList) {
const originalValue = <string>this.form.get('value').value;
if (originalValue !== null && typeof originalValue === 'string') {
let values = (<string>this.form.get('value').value).slice(1, -1).split(', ');
let values = (<string>this.form.get('value').value).slice(1, -1).split(', ').filter((value) => !value.includes('"'));
let specialValue = (<string>this.form.get('value').value).split('"').filter((value) => !value.startsWith('[') && !value.endsWith(']') && !values.includes(value));
specialValue.forEach(value => values.push(value));
if (!originalValue.startsWith('[') && !originalValue.endsWith(']')) {
values = undefined;
values = [originalValue];
@ -385,8 +387,8 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
parseTags() {
try{
let stringValue = this.form.get('value').value;
if (typeof stringValue === 'string') {
stringValue = (<string>stringValue).replace(new RegExp('{', 'g'), '{"').replace(new RegExp('=', 'g'), '":"').replace(new RegExp(',', 'g'), '",').replace(new RegExp(', ', 'g'), ', "').replace(new RegExp('}', 'g'), '"}');

Loading…
Cancel
Save