Deform – sequence of heterogeneous fields?

29 views
Skip to first unread message

Piotr Dobrogost

unread,
Aug 25, 2015, 11:27:37 AM8/25/15
to pylons-discuss
Hi!

I'm seeking advice on how to go about making it possible to dynamically add fields of different types to deform sequence widget. One idea is to have each element of a sequence be a mapping with fields of all possible types and hide all but the one desired. In other words there would be kind of variant type (each element of sequence would be of this type) when only one out of all possible fields would be visible and others would be hidden and discarded when submitted. What problems do you see with this approach? Is there a better way? I haven't found any previous discussion on this subject on this list – did I miss any?

Thank you in advance for sharing your thoughts on this.

Regards,
Piotr Dobrogost

Vincent Catalano

unread,
Aug 30, 2015, 2:00:41 PM8/30/15
to pylons-...@googlegroups.com
Hi Piotr,

One approach that you could try is having the types that you expect to validate against as a separate field consisting of your sequence types. When your form is submitted, you would read that field first and dynamically generate the schema you wish to validate the rest of your request against. Alternatively, you could have the validation type and element data as sub objects to your request and then validate each type based on the validation type field. That was probably a bit confusing, so are some examples of what your form posts would look like as JSON:

types: [ 'iPhone', 'android', 'windowsPhone'],
fields: [
  {
   iosVersion: '...'
   serialNumber: '...'
  },
  {
    androidVersion: '...',
    serialNumber: '...'
  },
  {
    windowsVersion: '...',
    productId: '...'
  }
]

- or -

fields: [
  {
    type: 'iPhone',
    data: {
      iosVersion: '...'
      serialNumber: '...'
  },
  {
    type: 'android',
    data: {
      androidVersion: '...',
      serialNumber: '...'
  },
  {
    type: 'windowsPhone',
    data: {
      windowsVersion: '...',
      productId: '...'
  }
]

I don't have too much experience with Deform, but I have used Colander quite extensively. Unfortunately, this will require some programming on your part to dynamically build the schema to validate against whenever your form is submitted.

Hope this helps!

-Vincent

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.



--
Vincent Catalano
Software Engineer and Web Developer,
(520).603.8944
Reply all
Reply to author
Forward
0 new messages