if ($val != 'true' && $val != 'false' && $val != 'null' && $val[0] != '{' && $val[0] != '[' && !is_numeric($val)) {
$val = json_encode($val, JSON_UNESCAPED_SLASHES);
}
+ elseif ($val[0] == '{' || $val[0] == '[') {
+ if (!is_array(json_decode($val, TRUE))) {
+ // Invalid JSON. Do not save.
+ continue;
+ }
+ }
$pos = strrpos($config, '};');
$key = preg_replace('/^config_/', 'config.', $key);
$setting = "\n\t{$key} = {$val};\n";
}
else {
$el.after('<span> = <input class="crm-form-text ' + (type==='Number' ? 'eight" type="number"' : 'huge" type="text"') + ' name="config_' + name + '"/></span>');
+ $el.next('span').find('input.crm-form-text[type=text]').change(validateJson);
}
} else {
$el.closest('div').remove();
return {results: list, text: 'id'};
}
+ function validateJson() {
+ var val = $(this).val();
+ $(this).parent().removeClass('crm-error');
+ if (val[0] === '[' || val[0] === '{') {
+ try {
+ JSON.parse(val);
+ } catch (e) {
+ $(this).parent().addClass('crm-error');
+ }
+ }
+ }
+
function addOption() {
$('#crm-custom-config-options').append($(configRowTpl({})));
- $('div:last input.crm-config-option-name', '#crm-custom-config-options').crmSelect2({
+ $('.crm-config-option-row:last input.crm-config-option-name', '#crm-custom-config-options').crmSelect2({
data: getOptionList,
formatSelection: function(field) {
return '<strong>' + field.id + '</strong> (' + field.type + ')';
border-bottom: 0 none;
padding: 3px 10px 1px !important;
}
+ .crm-config-option-row span.crm-error:after {
+ font-family: FontAwesome;
+ content: " \f071 Invalid JSON"
+ }
{/literal}</style>
{* Force the custom config file to reload by appending a new query string *}
<script type="text/javascript">