@@ -98,21 +98,39 @@ use constant FIELDS => [
9898 ' recitation' , ' comment' , ' permission' , ' password'
9999];
100100
101- # Note that only the editable fields need a type (i.e. all but user_id),
102- # and only the text fields need a size .
101+ # Note that only the editable fields need a type (i.e. all but user_id).
102+ # The fields of type text or number may also include optional attributes for the HTML input .
103103use constant FIELD_PROPERTIES => {
104104 user_id => { name => x(' Login Name' ) },
105- first_name => { name => x(' First Name' ), type => ' text' , size => 10 },
106- last_name => { name => x(' Last Name' ), type => ' text' , size => 10 },
107- email_address => { name => x(' Email Address' ), type => ' text' , size => 20 },
108- student_id => { name => x(' Student ID' ), type => ' text' , size => 11 },
109- status => { name => x(' Enrollment Status' ), type => ' status' },
110- accommodation_time_factor => { name => x(' Accommodation Time Factor' ), type => ' text' , size => 5 },
111- section => { name => x(' Section' ), type => ' text' , size => 3 },
112- recitation => { name => x(' Recitation' ), type => ' text' , size => 3 },
113- comment => { name => x(' Comment' ), type => ' text' , size => 20 },
114- permission => { name => x(' Permission Level' ), type => ' permission' },
115- password => { name => x(' Password' ), type => ' password' },
105+ first_name => { name => x(' First Name' ), type => ' text' , attributes => { size => 10 } },
106+ last_name => { name => x(' Last Name' ), type => ' text' , attributes => { size => 10 } },
107+ email_address => { name => x(' Email Address' ), type => ' text' , attributes => { size => 20 } },
108+ student_id => { name => x(' Student ID' ), type => ' text' , attributes => { size => 11 } },
109+ status => { name => x(' Enrollment Status' ), type => ' status' },
110+ accommodation_time_factor => {
111+ name => x(' Accommodation Time Factor' ),
112+ type => ' number' ,
113+ attributes => {
114+ size => 5,
115+ min => 1,
116+ step => ' any' ,
117+ title => ' Enter a decimal number that is greater than or equal to 1.'
118+ },
119+ perlValidate => sub {
120+ my $value = shift ;
121+ return $value !~ / ^(\d +(\.\d *)?|\.\d +)$ / || $value <= 0
122+ ? (x(
123+ ' Accomodation time factor for [_1] unchanged. '
124+ . ' A value was given that is not a decimal number or is not greater than or equal to 1.'
125+ ))[0]
126+ : 0;
127+ }
128+ },
129+ section => { name => x(' Section' ), type => ' text' , attributes => { size => 3 } },
130+ recitation => { name => x(' Recitation' ), type => ' text' , attributes => { size => 3 } },
131+ comment => { name => x(' Comment' ), type => ' text' , attributes => { size => 20 } },
132+ permission => { name => x(' Permission Level' ), type => ' permission' },
133+ password => { name => x(' Password' ), type => ' password' },
116134};
117135
118136sub pre_header_initialize ($c ) {
@@ -519,7 +537,14 @@ sub save_edit_handler ($c) {
519537
520538 for my $field ($User -> NONKEYFIELDS()) {
521539 my $newValue = $c -> param(" user.$userID .$field " );
522- $User -> $field ($newValue ) if defined $newValue ;
540+ next unless defined $newValue ;
541+ if (ref (FIELD_PROPERTIES()-> {$field }{perlValidate }) eq ' CODE'
542+ && (my $error = FIELD_PROPERTIES()-> {$field }{perlValidate }-> ($newValue )))
543+ {
544+ $c -> addbadmessage($c -> maketext($error , $userID ));
545+ next ;
546+ }
547+ $User -> $field ($newValue );
523548 }
524549 $db -> putUser($User );
525550
0 commit comments