Make fieldType a required property option. Check for the presence of either noFormPost or label.

This commit is contained in:
Colin Kuskie 2009-12-17 13:25:27 -08:00
parent 3b31069b1c
commit e1be2f9319
3 changed files with 41 additions and 7 deletions

View file

@ -125,10 +125,22 @@ An options hashref [need list of base options]. Any option which belongs to a f
is relegated to the form attribute of the property and removed from the list of is relegated to the form attribute of the property and removed from the list of
regular attributes. regular attributes.
=head4 fieldType
The type of field to be created by the form builder. This is required, and should be the name of
a WebGUI::Form plugin, with the initial letter lowercased.
=head4 noFormPost, label
Either or both of these must be passed in.
=cut =cut
sub property { sub property {
my ($meta, $name, %options) = @_; my ($meta, $name, %options) = @_;
if (! (exists $options{noFormPost} || exists $options{label}) ) {
Moose->throw_error("Must pass either noFormPost or label when making a property");
}
my %form_options; my %form_options;
my $prop_meta = $meta->property_meta; my $prop_meta = $meta->property_meta;
for my $key ( keys %options ) { for my $key ( keys %options ) {

View file

@ -28,7 +28,7 @@ Package WebGUI::Definition::Meta::Property::Asset
=head1 DESCRIPTION =head1 DESCRIPTION
Extends WebGUI::Definition::Meta::Property to provide Asset properties with Extends WebGUI::Definition::Meta::Property to provide Asset properties with
specific methods. specific methods. The tableName and fieldType class properties must be defined.
=head1 METHODS =head1 METHODS

View file

@ -24,9 +24,11 @@ my $called_getProperties;
attribute 'attribute1' => 'attribute1 value'; attribute 'attribute1' => 'attribute1 value';
property 'property1' => ( property 'property1' => (
arbitrary_key => 'arbitrary_value', arbitrary_key => 'arbitrary_value',
label => 'property1',
); );
property 'property2' => ( property 'property2' => (
nother_key => 'nother_value', nother_key => 'nother_value',
label => 'property2',
); );
# attributes create methods # attributes create methods
@ -62,7 +64,18 @@ my $called_getProperties;
use WebGUI::Definition::Asset; use WebGUI::Definition::Asset;
attribute tableName => 'asset'; attribute tableName => 'asset';
::dies_ok { property 'property1' => (); } 'must have a fieldType'; ::dies_ok { property 'property1' => (); } 'must have a fieldType';
::dies_ok { property 'property1' => (fieldType => 'text'); } 'must pass either a label or noFormPost flag';
::lives_ok { property 'property1' => (
fieldType => 'YUI Super Form',
noFormPost => '1',
);
} '... pass noFormPost flag';
::lives_ok { property 'property1' => (
fieldType => 'YUI Super Form',
label => 'JSON Powered Uber Widget',
);
} '... pass label';
} }
@ -73,9 +86,11 @@ my $called_getProperties;
attribute tableName => 'asset'; attribute tableName => 'asset';
property 'property2' => ( property 'property2' => (
fieldType => 'text', fieldType => 'text',
label => 'property2',
); );
property 'property1' => ( property 'property1' => (
fieldType => 'text', fieldType => 'text',
label => 'property1',
); );
my $written; my $written;
@ -143,13 +158,16 @@ my $called_getProperties;
attribute tableName => 'asset'; attribute tableName => 'asset';
property 'property1' => ( property 'property1' => (
fieldType => 'text' fieldType => 'text',
label => 'property1',
); );
property 'property2' => ( property 'property2' => (
fieldType => 'text' fieldType => 'text',
label => 'property2',
); );
property 'property3' => ( property 'property3' => (
fieldType => 'text' fieldType => 'text',
label => 'property3',
); );
package WGT::Class::Asset::Snippet; package WGT::Class::Asset::Snippet;
@ -158,10 +176,12 @@ my $called_getProperties;
attribute tableName => 'snippet'; attribute tableName => 'snippet';
property 'property10' => ( property 'property10' => (
fieldType => 'text' fieldType => 'text',
label => 'property10',
); );
property 'property11' => ( property 'property11' => (
fieldType => 'text' fieldType => 'text',
label => 'property11',
); );
package main; package main;
@ -200,9 +220,11 @@ my $called_getProperties;
attribute tableName => 'snippet'; attribute tableName => 'snippet';
property 'property10' => ( property 'property10' => (
fieldType => 'text', fieldType => 'text',
label => 'property10',
); );
property 'property1' => ( property 'property1' => (
fieldType => 'text', fieldType => 'text',
label => 'property1',
); );
package main; package main;