NAME
DBIx::Class::Valiant::Result::HTML::FormFields - Map DBIC Fields to HTML Form Fields
SYNOPSIS
package Example::Schema::Result::Person;
use base 'DBIx::Class::Core';
__PACKAGE__->load_components('Valiant::Result::HTML::FormFields');
Or just add to your base Result class:
package Example::Schema::Result;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->load_components('Valiant::Result::HTML::FormFields');
DESCRIPTION
This module extends DBIx::Class to provide functionality for mapping database fields to HTML form fields. It allows for easy generation and handling of form elements based on the schema's result class.
METHODS
register_column
$self->register_column($column, $info, @rest);
Registers a column with additional tag information. This method is overridden to add tag metadata for columns, which can be used for form generation.
Example:
__PACKAGE__->register_column('status', { data_type => 'varchar', size => 255, tags => ['select', 'option_value'] });
tags_by_column
my @tags = $self->tags_by_column($column);
Returns an array of tags associated with a column.
Example:
my @tags = $result->tags_by_column('status');
columns_by_tag
my @columns = $self->columns_by_tag($tag);
Returns an array of columns associated with a tag.
Example:
my @columns = $result->columns_by_tag('select');
add_select_options_rs_for
$class->add_select_options_rs_for($column, $code);
Adds a result set generator code reference for a select field.
Example:
__PACKAGE__->add_select_options_rs_for('status', sub {
my ($self, %options) = @_;
return $self->result_source->schema->resultset('Status')->search({}, \%options);
});
select_options_rs_for
my ($rs, $label_method, $value_method) = $self->select_options_rs_for($column, %options);
Returns a result set, label method, and value method for a select field.
Example:
my ($rs, $label_method, $value_method) = $result->select_options_rs_for('status');
select_options_for
my @options = $self->select_options_for($column, %options);
Returns a list of select options for a column. This is a array of arrayrefs where the first element is the label and the second element is the value.
Example:
my @options = $result->select_options_for('status');
add_checkbox_rs_for
$class->add_checkbox_rs_for($column, $code);
Adds a result set generator code reference for a checkbox field.
Example:
__PACKAGE__->add_checkbox_rs_for('roles', sub {
my ($self, %options) = @_;
return $self->result_source->schema->resultset('Role')->search({}, \%options);
});
checkbox_rs_for
my $rs = $self->checkbox_rs_for($column, %options);
Returns a result set for a checkbox field.
Example:
my $rs = $result->checkbox_rs_for('roles');
checkboxes_for
my @checkboxes = $self->checkboxes_for($column, %options);
Returns a list of checkboxes for a column. This is an array of arrayrefs where the first element is the label and the second element is the value.
add_radio_button_rs_for
$class->add_radio_button_rs_for($column, $code);
Adds a result set generator code reference for a radio button field.
Example:
__PACKAGE__->add_radio_button_rs_for('gender', sub {
my ($self, %options) = @_;
return $self->result_source->schema->resultset('Gender')->search({}, \%options);
});
radio_button_rs_for
my $rs = $self->radio_button_rs_for($column, %options);
Returns a result set for a radio button field.
Example:
my $rs = $result->radio_button_rs_for('gender');
add_radio_buttons_for
$class->add_radio_buttons_for($column, $code);
Add an array of radio button labels Example:
__PACKAGE__->add_radio_buttons_for('status', sub($self, %options) {
return $self->status_list;
});
sub status_list($self) { return qw( pending active inactive ) }
radio_buttons_for
my @buttons = $self->radio_buttons_for($column, %options);
Returns a list of radio buttons for a column.
Example:
my @buttons = $result->radio_buttons_for('preferences');
add_form_field_for
$class->add_form_field_for($column, $code);
Adds a form field generator code reference for a column.
Example:
__PACKAGE__->add_form_field_for('first_name', sub {
my ($self, $column) = @_;
return $self->first_name;
});
Note: If no form field is defined for a column, the module will automatically read the value of the column via the _auto_read_attribute_for_html
method.
has_form_fields
my $bool = $self->has_form_fields;
Checks if the result class has form fields.
has_form_field
my $bool = $self->has_form_field($attribute);
Checks if the result class has a form field for an attribute.
read_form_field_for
my $value = $self->read_form_field_for($attribute);
Reads the value of a form field for an attribute.
read_attribute_for_html
my $value = $self->read_attribute_for_html($attribute);
Reads the value of an attribute for HTML.
_auto_read_attribute_for_html
my $value = $self->_auto_read_attribute_for_html($attribute);
Automatically reads the value of an attribute for HTML.
AUTHOR
John Napiorkowski email:jjnapiork@cpan.org
SEE ALSO
COPYRIGHT & LICENSE
Copyright 2020, John Napiorkowski email:jjnapiork@cpan.org
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.