Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Nedeľa, 29. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Setting Default value of a drop down to null

phpMyEdit Configuration     Setting Default value of a drop down to null
Odoslať novú tému   Odpovedať na tému    
 
depika     Založený: 22.05.2006   Príspevky: 5  
Príspevok Zaslal: 2006-05-29 17:05
Návrat hore  Odpovedať s citátom     

I am getting the values in one field from another table. My problem is that when entering data the first record is selected. I want to have a null first value in the dropdown and since this field is required to have a popup message saying that this value cannot be null.

I have managed to set the first value to be null but on save the code seems to find that the field has value and is not null.

Below is my code
Kód:

$opts['fdd']['ISLAND'] = array(

  'name'     => 'ISLAND',

  'select'   => 'D',

  'maxlen'   => 50,

  'sort'     => true,

  'required' => true
);

$opts['fdd']['ISLAND']['values']['table'] = 'ISLAND';
$opts['fdd']['ISLAND']['values']['column'] = 'ID';
$opts['fdd']['ISLAND']['values']['description'] ='ISLAND_EL' ;
$opts['fdd']['ISLAND']['values2'] = array('' => NULL);


I would appreciate your help

 
mushroom     Založený: 14.05.2006   Príspevky: 8  
Príspevok Zaslal: 2006-05-31 17:23
Návrat hore  Odpovedať s citátom     

Hm... I think you need to use
Kód:
$opts['fdd']['col_name']['js']['required'] = true;
or try regular expression to make your validation more powerful.

Example:
Kód:
$opts['fdd']['col_name']['js']['regexp'] = '/^[0-9]*$/';


Read this

 
depika     Založený: 22.05.2006   Príspevky: 5  
Príspevok Zaslal: 2006-05-31 20:01
Návrat hore  Odpovedať s citátom     

I added what you mentioned but still this field is not required if nothing gets selected. Does it matter that the field is a dropdown that the code doesn't work?

Is there a way to use the selected option of a dropdown?

Despoina

 
mushroom     Založený: 14.05.2006   Príspevky: 8  
Príspevok Zaslal: 2006-06-01 20:39
Návrat hore  Odpovedať s citátom     

depika Napísal:
I added what you mentioned but still this field is not required if nothing gets selected. Does it matter that the field is a dropdown that the code doesn't work?

Is there a way to use the selected option of a dropdown?

Despoina


So, when I asked your first post, I didn't test anywhere. And when you said, that ['js']['required'] and ['js']['regexp'] hadn't work, I decided to create simply example. So result was "fine" very much.

When you set validation for a dropdown PME create js-code.
For example:
Kód:
function PME_js_form_control(theForm)
{

   if (theForm.PME_data_title.selectedIndex == -1) {
      alert("Please enter TITLE.");
      theForm.PME_data_title.focus();
      return false;
   }

   return true;
}


But... Where are my js-required and regexp validations?! PME only checks the number of the selected option. It must be >=0. But if you set validation for the text field all's right. So... PME doesn't allow regexp and empty-value validation for a dropdown. I think that it's logical, isn't it? Are you sure that you really need it?

 
paolodp     Založený: 06.07.2006   Príspevky: 11  
Príspevok Zaslal: 2006-08-03 07:21
Návrat hore  Odpovedať s citátom     

hi mushroom,

I have read this post several times and, sorry, I dont understand it. So, please,

1) may you explain me how to set default of a dropdown to '' when it is populated from a mysql table (without adding the value '' in the table ) ?

2) if ...['js']['required']=true is used, it validates correctly ?

TY very much for help

 
mushroom     Založený: 14.05.2006   Príspevky: 8  
Príspevok Zaslal: 2006-08-14 09:56
Návrat hore  Odpovedať s citátom     

paolodp Napísal:
1) may you explain me how to set default of a dropdown to '' when it is populated from a mysql table (without adding the value '' in the table ) ?


If there are not '' in the dropdown you can't set it default.

paolodp Napísal:
2) if ...['js']['required']=true is used, it validates correctly ?


No, it doesn't. PME generates it's own validation code for dropdowns. You may set ['js']['required']=true and look at the results.

Sorry, if my english so bad... =)

 
marty     Založený: 10.07.2006   Príspevky: 2  
Príspevok Zaslal: 2006-09-07 21:41
Návrat hore  Odpovedať s citátom     

Firstofall, i think you do not use the "values2"-Option correctly: instead of

Kód:
$opts['fdd']['ISLAND']['values2'] = array('' => NULL);


it should be

Kód:
$opts['fdd']['ISLAND']['values2'] = array(NULL => '');

if you want NULL in the DB, as the documentation says
Citácia:
...that array keys will be stored into database and array values will be printed out in input section boxes...


But also then it won't work correctly, because the PHPMyEdit-Class function do_change_record() generates a (what I think is not correct) query of the form

Kód:
UPDATE... SET field='NULL'

which sets the field to numeric 0 -
the query should be
Kód:
UPDATE... SET field=NULL


(I'm surprised how tolerant MySQL is, because all fields in the generated Query are quoted)

So, as a workaround, if your field doesn't has to be NULL and 0 is enough, then take

Kód:
$opts['fdd']['ISLAND']['values2'] = array(0 => '');
and it should work.

Hope that helps,

Martin

 
michal     Založený: 17.06.2003   Príspevky: 537   Bydlisko: Slovakia
Príspevok Zaslal: 2006-09-08 14:42
Návrat hore  Odpovedať s citátom     

just use trigger before with single line like:
if($newvals['key']==0) unset($newvals['key']);

 
sagiben     Založený: 27.01.2009   Príspevky: 15  
Príspevok Zaslal: 2009-07-25 16:41
Návrat hore  Odpovedať s citátom     

I'm having the same problem,
I still don't know how to solve it but I guess there's a bug in PME because selectedIndex can never be -1 and thus
the 'if' statement will always fail.

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov