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

Document how the form parser works #41

Closed
3 tasks
aeneasr opened this issue Jul 24, 2019 · 2 comments
Closed
3 tasks

Document how the form parser works #41

aeneasr opened this issue Jul 24, 2019 · 2 comments
Assignees
Labels
package/selfservice/password Affects the Password Self Service Strategy

Comments

@aeneasr
Copy link
Member

aeneasr commented Jul 24, 2019

The registration form parser supports:

  • numbers (float64)
  • boolean
  • string

It also supports json paths for traits in the form of traits[foo.bar.baz] using sjson.

Examples

  • Include examples from sjson docs or build our own

Limitations

Nested Items

The way json schema works is that required propagates to deeper levels. If key baz of foo.bar.baz is always required, foo and bar must also be required.

When using form fields, this is very challenging to automate for us at the moment (explain here that go json schema is limited). Basically, the form payload would need to send {foo:{bar:{}}}, otherwise the only error you will see is that foo is required, which can then not be properly assigned to the actual <input name="traits[foo.bar.baz]"> because the keys do not match.

Workaround:

How To: Nested elements

Assuming a traits model:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "name": {
      "type": "object",
      "properties": {
        "first": {
          "type": "string"
        },
        "last": {
          "type": "string"
        }
      }
    }
  }
}

You could address name.first this with a form name of:

<input type=checkbox" value="true" name="traits[path.to.my.boolean]"

How To: Checkbox to boolean:

If it's not checked:

<input type=checkbox" value="true" name="traits[path.to.my.boolean]" />

If the checkbox is checked:

<input type=checkbox" value="true" name="traits[path.to.my.boolean]" checked />

If the checkbox should be toggled based on the form value (e.g. when form validation fails):

<input type=checkbox" value="true" name="traits[path.to.my.boolean]" checked={{ this.value===true }} />

How To: Array elements

  • Todo: Add array element docs
@aeneasr aeneasr added module:docs package/selfservice/password Affects the Password Self Service Strategy labels Jul 24, 2019
@aeneasr aeneasr added this to the v0.0.1 milestone Jul 24, 2019
@aeneasr aeneasr self-assigned this Aug 2, 2019
@aeneasr aeneasr modified the milestones: v0.0.1, v0.0.2 Aug 6, 2019
@aeneasr aeneasr modified the milestones: v0.0.2, v0.0.1 Nov 4, 2019
@aeneasr
Copy link
Member Author

aeneasr commented Nov 22, 2019

The new form parser no longer uses traits[path.to.my.boolean] but instead traits.path.to.my.boolean

@aeneasr
Copy link
Member Author

aeneasr commented Jan 28, 2020

done

@aeneasr aeneasr closed this as completed Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package/selfservice/password Affects the Password Self Service Strategy
Projects
None yet
Development

No branches or pull requests

1 participant