Gossamer Forum
Home : Products : DBMan SQL : Discussion :

How to create select field?

Quote Reply
How to create select field?
How to create a new column, which will result following Select form HTML code?:
Code:
<select name="test">
<option value="" selected>Please select a value</option>
<option value="(1) value1">(1) value1</option>
<option value="(2) value2">(2) value2</option>
<option value="(3) value3">(3) value3</option>
<option value="(4) value4">(4) value4</option>
</select>


The select form should have no default value selected or selected the "Please select a value" only.
The user must select a value so it should be NOT NULL, but should have no default value.

Currently the added 'test' column looks like this in the .def file:
Code:
'test' => {
'file_max_size' => '',
'file_save_in' => '',
'file_save_scheme' => 'HASHED',
'file_save_url' => '',
'form_display' => 'Test',
'form_names' => [
'(1) value1',
'(2) value2',
'(3) value3',
'(4) value4'
],
'form_size' => '',
'form_type' => 'SELECT',
'form_values' => [
'(1) value1',
'(2) value2',
'(3) value3',
'(4) value4'
],
'not_null' => '1',
'pos' => '8',
'regex' => '',
'type' => 'ENUM',
'values' => [
'(1) value1',
'(2) value2',
'(3) value3',
'(4) value4'
],
'weight' => ''
}


But the problem is, that <%Dbsql::HTML::generate_select('test')%> doesn't generate the awaited select HTML code. It always has a selected value, but should be not selected by default:
Code:
<select name="test">
<option value="(1) value1">(1) value1</option>
<option value="(2) value2">(2) value2</option>
<option value="(3) value3">(3) value3</option>
<option value="(4) value4">(4) value4</option>
</select>


Any ideas, how to setup the column, to have the correct select HTML code generated?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: Apr 29, 2005, 4:32 PM
Quote Reply
Re: [webmaster33] How to create select field? In reply to
Hi,
I'm not sure that I understand what you are trying to do but I use the following code for 2 reasons -
1/ My test field is a required field (NOT NULL) so if the user doesn't select from the list it will generate an error because the option value for "Please select a value" is set at "".
2/ If another required field on the form is not entered and the form is re-loaded my test field will be set to what the user has just selected so they don't have to re-select everything again.

Code:
<select name="test">
<%if test%>
<option value="<%test%>" selected><%test%></option>
<%else%>
<option value="" selected>Please select a value</option>
<%endif%>
<option value="(1) value1">(1) value1</option>
<option value="(2) value2">(2) value2</option>
<option value="(3) value3">(3) value3</option>
<option value="(4) value4">(4) value4</option>
</select>
As I said, I'm not sure what you are trying to do but maybe you can modify my code to do what you want. If not please try to explain it a bit more.
Simon.
Quote Reply
Re: [jai] How to create select field? In reply to
The problem is that I would like an auto-generated form.
Your solution is a hard-coded template solution, which doesn't depend on database field content.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] How to create select field? In reply to
Just simply change the code around line #377 in Dbsql/HTML.pm like:

....
return $tags->{home}->{disp}->select ( {
name => $col,
values => $form_values,
names => $form_names,
value => $selected,
blank => 1,
});

TheStone.

B.
Quote Reply
Re: [TheStone] How to create select field? In reply to
Could you commit this change to the CVS?
I don't want to lose upgrade compatibility of it.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [TheStone] How to create select field? In reply to
I'm not sure if I can change the blank value in this case...
For example to show: "Please select a value"

Is this possible?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] How to create select field? In reply to
No, unless you customize the template instead.

TheStone.

B.

Last edited by:

TheStone: May 2, 2005, 3:52 PM
Quote Reply
Re: [TheStone] How to create select field? In reply to
Would be fine to add this as an option to the config.
In LSQL I solved this using a plugin, but would be the time to have this empty field text configurable in both LSQL and DBMan SQL.
In LSQL this empty field text in represented by '---' by this is ugly.

In GT::SQL::Display::HTML::select it displays in line 291:
Code:
$blank and ($out .= qq~<option value="">---</option>~);

I would change to
Code:
$blank && $blank_text && ($out .= qq~<option value="">$blank_text</option>~);
Of course the 'blank_text' is an input option.

So the select code call would be look like this:
Code:
return $tags->{home}->{disp}->select ( {
name => $col,
values => $values,
value => $selected,
blank => 1,
blank_text => 'Please select a value',
});

Much better if we avoid English hardcoding in core code so we can use language :
Code:
return $tags->{home}->{disp}->select ( {
name => $col,
values => $values,
value => $selected,
blank => 1,
blank_text => ${$app_name . '::language'}->('REQUIRE_CGI'),
});
The $app_name can be acquired by a separate library. I have the base code to identify the currently running app, and get the $app_name. I can send it to you if you want.

Let me know, if you would accept to add this blank_text option to the GT::SQL::Display::HTML module.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: May 3, 2005, 4:07 AM
Quote Reply
Re: [TheStone] How to create select field? In reply to
Any comment on the suggested modification?
Would you commit this it into CVS?

This would be the part which should be changed (parts in red are added or changed):
Code:
my $blank_text = exists $opts->{blank_text} ? $opts->{blank_text} : '---';
$blank && $blank_text && ($out .= qq~<option value="">$blank_text</option>~);

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...