[Maypole] AsForm again - selects?

Dave Howorth Dave.Howorth@acm.org
Thu, 09 Dec 2004 23:56:43 +0000


Peter Speltz wrote:
> Dave Howorth wrote:
>> I'm looking at the addnew form for a table that has a foreign key
>> that is allowed to be null. AsForm has generated a select box for
>> it, which is good (modulo the other issues we know about :)  But
>> it's populated the select box with all the existing keys. There
>> doesn't seem to be any way to say that I want a NULL value for this
>> field in my new record.
> 
> Not sure i understand. Are you saying you want a select box with a
> NULL option on top so you can select that?  Search form does that by
> unshifting a HTML::Element (option) to the respective select element.
> See that template.

Yes, that's exactly it. Thanks a million for the pointer, Peter.

> I've been working on AsForm and this was a question i had, should it
> add a "None" option by default.  Can't remember but something told me
> this was a bad idea.  Oh yeah, NOT backward compatible.  Most of my
> cases i don't need this and its easy to add one on your own.  But
> some apps may need this more times than not in which case they may
> benifit if the exception was deleting the first "NONE" option from
> the select box generated by AsForm rather than adding a NONE option.
> Thoughts anyone

It seems to me there are several cases :)
There's a difference between the desired behaviour of a search form and 
an add new form, and there's a difference between the desired behaviour 
depending on whether the data type allows NULL or not.

Data Type    Operation    Behaviour
---------    ---------    ---------
NOT NULL     search       allow existing values or "Don't Care"
NOT NULL     add new      allow existing values only *
can be NULL  search       allow existing values, NULL and "Don't Care"
can be NULL  add new      allow existing values and NULL

* There's conceivably another possible option here, which is a push 
button to create a new value of the associated record first.

IMHO, it's more natural for the code (i.e. AsForm) to generate all the 
data-dependent values (i.e. all the valid values including NULL where 
required). I could be persuaded either way about the "Don't Care" (i.e. 
whether it's more natural for the code or the template) but that bit 
isn't broken, so let's not fix it!

I'm eagerly awaiting your revised code :)

Cheers, Dave