Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Title with value of array property #3

Open
thenewguy opened this issue Dec 19, 2014 · 1 comment
Open

Title with value of array property #3

thenewguy opened this issue Dec 19, 2014 · 1 comment

Comments

@thenewguy
Copy link

Support the use of {{ value }} template to reference properties with an object type

I.e. with the following, the titles would be "Friend Foo" and "Friend Bar" if two friends were added with nicknames of "Foo" and "Bar"

{
  "schema": {
    "friends": {
      "type": "array",
      "items": {
        "type": "object",
        "title": "Friend {{ value.nick }}",
        "properties": {
          "nick": {
            "type": "string",
            "title": "Nickname",
            "required": true
          },
          "gender": {
            "type": "string",
            "title": "Gender",
            "enum": [ "male", "female", "alien" ]
          },
          "age": {
            "type": "integer",
            "title": "Age"
          }
        }
      }
    }
  }
}
@ulion
Copy link
Owner

ulion commented Dec 29, 2014

"Friend {{ value.nick }}" such title should not be in the schema, which should be in the form definition.

Indeed jsonform support set title "Friend {{ values.friends[].nick }}", but which only works for the initial value, not update when the nick changes.

Or, if you are using tabarray type, which support setup "valueInLegend: true" for the nick form element, then setup 'legend: "Friend {{value}}"' for the array element, which support dynamic update the tab name according to the value of one of the sub-elements of the array element.

As a workaround, you can always write your own on change function to archive what you want, e.g.

$('form').on('change', 'input[name^="friends["][name$="].nick"]', function(e) {
  var val = $(this).val();
  $(this).parents('.jsonform-node').eq(1).find('> legend').text('Friend ' + val);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants