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

Dynamically add items into the page #4

Open
valorin opened this issue Feb 17, 2016 · 7 comments
Open

Dynamically add items into the page #4

valorin opened this issue Feb 17, 2016 · 7 comments
Labels
Milestone

Comments

@valorin
Copy link

valorin commented Feb 17, 2016

For Habits I need to add and remove new form elements for each Habit that the user wants to manage. I've looked through the readme, but it doesn't sound like this is supported in Clay.

Is this something that can be considered and added to the roadmap?

@keegan-lillo
Copy link
Contributor

How would you go about setting appKeys? How does the current implementation work as far as serializing the data?

@valorin
Copy link
Author

valorin commented Feb 18, 2016

My current implementation doesn't actually serialise any data back to the Pebble - it sends it to my server via an ajax post request, but that's not really the point. I should probably open another issue for that though - since it's a very common use case if you're working on a timeline enabled app. :-)

The way I currently handle it is by using html arrays. Consider these basic form elements:

<!-- block one -->
<input type="text" name="name[1]" value="nameValue1">
<input type="text" name="description[1]" value="descValue1">

<!-- block two -->
<input type="text" name="name[2]" value="nameValue2">
<input type="text" name="description[2]" value="descValue2">

The data would be received with an array for each of name and description:

name: ["nameValue1", "nameValue2"],
description: ["descValue1", "descValue2"]

I don't really know how this would apply to appKeys, etc... but it's definitely a valid use case for complex apps with multiple configurable "things".

@keegan-lillo
Copy link
Contributor

Interesting...
Maybe if there was a component called something like "dynamic-group" that had very similar syntax to a "section" but would have an add and remove buttons as well as the ability to re-order. The config would look something like:

{
  type: 'dynamic-group',
  structure: [
    // Any combination of components
    {
      type: 'input',
      appKey: 'name',
      label: 'Name'
    },
    {
      type: 'color',
      appKey: 'fave_color',
      'Favorite Color'
    }
  ]
}

And would end up being serialized into something like:

{
  name: ['Joe', 'Fred'],
  fave_color: [0xFF0000, 0x00FF00]  
}

@valorin
Copy link
Author

valorin commented Feb 24, 2016

Yeah, something like that should do what I need it to do! :-)

@pautomas
Copy link

Sorry for bumping this one, but wanted to add one requests for the future dynamic-group component: the ability to define the max and min number of items in the group. ie: if my config page allows the user to define their favorite contacts to a maximum of 10 the component should look something like:

 {
  type: 'dynamic-group',
  min-items: 1, // this might be the value by default
  max-items: 10,
  structure: [
    {
      type: 'input',
      appKey: 'name',
      label: 'Name'
    },
    {
      type: 'color',
      appKey: 'fave_color',
      'Favorite Color'
    }
  ]
}

@ignat980
Copy link

Is this currently possible via a Clay Custom function, or is it impossible unless the package is updated to handle dynamic fields?

@keegan-lillo
Copy link
Contributor

@ignat980 You could achieve it with a custom component, but it will not be trivial. Sorry.

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

No branches or pull requests

4 participants