Make fieldType a required property option. Check for the presence of either noFormPost or label.
This commit is contained in:
parent
3b31069b1c
commit
e1be2f9319
3 changed files with 41 additions and 7 deletions
|
|
@ -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
|
||||
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
|
||||
|
||||
sub property {
|
||||
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 $prop_meta = $meta->property_meta;
|
||||
for my $key ( keys %options ) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ Package WebGUI::Definition::Meta::Property::Asset
|
|||
=head1 DESCRIPTION
|
||||
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -24,9 +24,11 @@ my $called_getProperties;
|
|||
attribute 'attribute1' => 'attribute1 value';
|
||||
property 'property1' => (
|
||||
arbitrary_key => 'arbitrary_value',
|
||||
label => 'property1',
|
||||
);
|
||||
property 'property2' => (
|
||||
nother_key => 'nother_value',
|
||||
label => 'property2',
|
||||
);
|
||||
|
||||
# attributes create methods
|
||||
|
|
@ -62,7 +64,18 @@ my $called_getProperties;
|
|||
use WebGUI::Definition::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';
|
||||
property 'property2' => (
|
||||
fieldType => 'text',
|
||||
label => 'property2',
|
||||
);
|
||||
property 'property1' => (
|
||||
fieldType => 'text',
|
||||
label => 'property1',
|
||||
);
|
||||
|
||||
my $written;
|
||||
|
|
@ -143,13 +158,16 @@ my $called_getProperties;
|
|||
|
||||
attribute tableName => 'asset';
|
||||
property 'property1' => (
|
||||
fieldType => 'text'
|
||||
fieldType => 'text',
|
||||
label => 'property1',
|
||||
);
|
||||
property 'property2' => (
|
||||
fieldType => 'text'
|
||||
fieldType => 'text',
|
||||
label => 'property2',
|
||||
);
|
||||
property 'property3' => (
|
||||
fieldType => 'text'
|
||||
fieldType => 'text',
|
||||
label => 'property3',
|
||||
);
|
||||
|
||||
package WGT::Class::Asset::Snippet;
|
||||
|
|
@ -158,10 +176,12 @@ my $called_getProperties;
|
|||
|
||||
attribute tableName => 'snippet';
|
||||
property 'property10' => (
|
||||
fieldType => 'text'
|
||||
fieldType => 'text',
|
||||
label => 'property10',
|
||||
);
|
||||
property 'property11' => (
|
||||
fieldType => 'text'
|
||||
fieldType => 'text',
|
||||
label => 'property11',
|
||||
);
|
||||
|
||||
package main;
|
||||
|
|
@ -200,9 +220,11 @@ my $called_getProperties;
|
|||
attribute tableName => 'snippet';
|
||||
property 'property10' => (
|
||||
fieldType => 'text',
|
||||
label => 'property10',
|
||||
);
|
||||
property 'property1' => (
|
||||
fieldType => 'text',
|
||||
label => 'property1',
|
||||
);
|
||||
|
||||
package main;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue