Skip to content
This repository has been archived by the owner on Mar 7, 2019. It is now read-only.

Allow Complex (e.g., JSON) Default Property Values #417

Closed
Nicholas-Westby opened this issue Jul 13, 2017 · 4 comments
Closed

Allow Complex (e.g., JSON) Default Property Values #417

Nicholas-Westby opened this issue Jul 13, 2017 · 4 comments
Assignees

Comments

@Nicholas-Westby
Copy link
Contributor

When adding a property to an Archetype fieldset, a default value can be specified:

complex-default

That works OK when the value is a simple text value. However, it doesn't seem to work when it's a complex data type (in this case, a blob of JSON).

On a related note, would be great if this were a text area rather than a text line (that way, complex data that spans multiple lines can more easily be read).

FYI, the data type I'm trying to set a default for in this case is a Formulate form configuration picker.

@Nicholas-Westby
Copy link
Contributor Author

By the way, here's how Umbraco correctly stores a picked form value:

{"alias":"form","value":"{\r\n  \"id\": \"397c9fbd642a4e2098487572fafe7338\"\r\n}"}

My guess would be that the way this is stored is not how it's sent to the AngularJS directive. I would guess it converts the string value into a JSON object. I would further suspect that the reason this doesn't work with Archetype is that Archetype is setting this on the client side, which bypasses Umbraco's server-side JSON detection logic (i.e., it is passed as a string rather than as JSON). Haven't actually looked at the code though, so that's just a guess.

The simplest solution I can think of would be to add a checkbox under the "Default Value" field that says "Treat Default Value as JSON?" Or maybe you could have a drop down that indicates the format of the default value (the initial value being "Plain Text", and another option being "JSON").

@kjac kjac closed this as completed in c836498 Aug 9, 2017
@kjac
Copy link
Contributor

kjac commented Aug 9, 2017

Actually Archetype already tries to parse the default values to JSON objects. Unfortunately there was an error in the subsequent value assignment, which forced the parsed object into a string.

It's fixed, will be part of the next release.

Please note that the JSON used for default values must validate with https://jsonlint.com/ - or in other words, must be valid for JSON.parse().

@kjac kjac self-assigned this Aug 9, 2017
@kjac
Copy link
Contributor

kjac commented Aug 9, 2017

Reopening this until we have a new release.

@kjac kjac reopened this Aug 9, 2017
@kjac
Copy link
Contributor

kjac commented Aug 18, 2017

Fixed in v1.15.1

@kjac kjac closed this as completed Aug 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants