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

Question: Any way to handle nested/related fields? #25

Open
jeffcarbs opened this issue Nov 19, 2015 · 1 comment
Open

Question: Any way to handle nested/related fields? #25

jeffcarbs opened this issue Nov 19, 2015 · 1 comment

Comments

@jeffcarbs
Copy link
Contributor

I'm building a form and I'm running into some issues with nested resources. Here's a simplified version of my data model:

{
  "id": 123,
  "name": "Bob Smith",
  "email_addresses": [
    {
      "id": 456,
      "label": "home",
      "address": "[email protected]"
    },
    {
      "id": 789,
      "label": "work",
      "address": "[email protected]"
    }
  ]
}

Here's my current form (note that it's only capturing the address field). This form will eventually need to support more complex inputs like mailing address.

[
  {
    title: 'Account information',
    cells: [
      {
        title: 'Name',
        name: :name,
        type: :name,
        placeholder: 'Name'
      }
    ]
  },
  {
    title: 'Email addresses',
    name: :email_addresses,
    options: [:insert, :delete, :reorder],
    cells: [
      {
        title: '',
        name: :address,
        type: :email,
        placeholder: 'Email address'
        # Needs to (but doesn't) capture the id/label
      }
    ]
  }
]

I think the underlying question is: is there a way for one "form row" to support multiple fields/inputs without needing to use a separate screen.

I'd really like it to work similar to the Apple contacts works where all multiple inputs for the same field appear inline/adjacent to one another. Is there any way to do that with this gem currently?

@bmichotte
Copy link
Owner

I don't think and didn't find any hint on how to do that with XLForm.

I guess it should be possible by adding playing with cell_class in which you add multiple fields

class AddressCell < PM::XLFormCell
  # init, add @label / @email
  def update
    super

    @label.text = value['label']
    @email.text = value['email'] 
  end
end

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