allow fieldtype to be configure to set "type" in the fields
authorTony Cook <tony@develop-help.com>
Thu, 20 Mar 2014 23:44:29 +0000 (10:44 +1100)
committerTony Cook <tony@develop-help.com>
Sat, 9 May 2015 04:06:42 +0000 (14:06 +1000)
This will allow it to be used with the request object cgi_fields()
method

site/cgi-bin/modules/BSE/MetaMeta.pm

index 546139eada986f2c57edd16d1b987d8b6fa36d89..adadc20a5384e557cdb734c621040429a92a5707 100644 (file)
@@ -3,7 +3,7 @@ use strict;
 use Carp qw(confess);
 use Image::Size;
 
-our $VERSION = "1.002";
+our $VERSION = "1.003";
 
 =head1 NAME
 
@@ -120,6 +120,14 @@ How to display this field.  May be ignored depending on C<type>.
 
 sub htmltype { $_[0]{htmltype} }
 
+=item fieldtype
+
+How to parse this field.  May be ignored depending on type.
+
+=cut
+
+sub fieldtype { $_[0]{fieldtype} }
+
 =item width
 
 Display width.  May be ignored depending on C<type>.
@@ -186,13 +194,19 @@ sub field {
 
   my %field =
     (
-     %{$field_defs{$self->type}},
      description => scalar $self->title,
      units => scalar $self->unit,
      rules => scalar $self->rules,
-     type => scalar $self->type,
+     rawtype => scalar $self->type,
      htmltype => scalar $self->htmltype,
+     type => scalar $self->fieldtype,
+     width => scalar $self->width,
+     height => scalar $self->height,
     );
+  my $defs = $field_defs{$self->type};
+  for my $key (keys %$defs) {
+    defined $field{$key} or $field{$key} = $defs->{$key};
+  }
   if ($self->type =~ /^(?:multi)?enum$/) {
     my $values = [ $self->values ];
     my $labels = [ $self->labels ];
@@ -206,8 +220,14 @@ sub field {
        values => \@values,
       };
   }
+  my %fields = ( $self->name => \%field );
 
-  return \%field;
+  require BSE::Validate;
+  my $configured = 
+    BSE::Validate::bse_configure_fields({ $self->name => \%fields }, BSE::Cfg->single,
+                                       $self->validation_section);
+
+  return $fields{$self->name};
 }
 
 =item name
@@ -344,11 +364,12 @@ sub new {
      type => "string",
      unit => '',
      help => '',
-     width => 60,
-     height => 40,
+     fieldtype => "",
      @_
     );
 
+  
+
   $opts{cfg} && $opts{cfg}->can("entry")
     or confess "Missing or invalid cfg parameter";
   $opts{name}
@@ -407,7 +428,7 @@ sub new {
 }
 
 sub keys {
-  qw/title help rules ro values labels type data_name width_name height_name cond unit htmltype width height/;
+  qw/title help rules ro values labels type data_name width_name height_name cond unit htmltype width height fieldtype/;
 }
 
 sub retrieve {