On Saturday, November 23, 2013 11:44:05 PM UTC-8, Mark Li wrote:
>
> I think I've found an optimal solution for this.
>
> Since the validators for my table are only enforced at the form-level, I
> first insert a blank playlists record, and then use a SQLFORM or CRUD to
> update the newly inserted record. I can't submit an incomplete form, but I
> can insert an incomplete record and mark the "finished" column as false.
>
> This way, the playlist id already exists and I can save the
> playlist_tracks to the reference table. The validators will still apply
> when the user submits the form.
>
>
As long as the "finished" field is adequate protection from having an
incomplete or invalid entry messing up some of your db table processing at
a later time if the user doesn't correct the form. I think I would have
done something with storing partials in the session, but maybe one the
Respected Regulars has some alternative advice.
/dps
> On Saturday, November 23, 2013 6:50:19 PM UTC-8, Mark Li wrote:
>>
>>
>> I currently have 2 tables as follows, with a form containing values both
>> tables
>>
>> db.define_table('playlist',
>> Field('title', notnull=True),
>> Field('description'),
>> Field('tags'),
>> Field('genre', 'reference genre')
>> Field('finished', 'boolean')
>> )
>>
>> db.define_table('playlist_tracks',
>> Field('playlist', 'reference playlist'),
>> Field('songname')
>> )
>>
>>
>>
>> The form to add playlist_tracks is dynamic; a user enters a songname,
>> which appends an input element with value=songname. When the user submits
>> the form, if the form does not pass validation, then the playlist_tracks
>> will all disappear when the page reloads, since they were added dynamically.
>>
>> I want to prevent this from happening, as it can be very time consuming
>> to add all the playlist tracks. I want to save the playlist_tracks in the
>> reference table so they don't disappear, but it's not possible because
>> there is no 'playlist' reference (the playlist didn't pass validation). I
>> also want to give the user the option of "saving" an incomplete form to
>> work on later, which has the same problem because the incomplete form might
>> not pass validation, and thus there is no 'playlist' reference.
>>
>> What would be the best method of saving this incomplete form, so the
>> dynamically added playlist tracks will have a playlist reference?
>>
>> I was thinking about inserting the record with dummy default values,
>> after validation fails, but that has the disadvantage of automatically
>> filling a required field that the user didn't choose. For example, if a
>> user doesn't enter a title and doesn't select a genre from the select
>> drop-down, then after validation fails, I'll insert the record with
>> "Untitled Playlist" and genre==1 (and all other fields that passed
>> validation would remain unchanged) but still show the form errors.
>>
>>
>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.