Chandra
view release on metacpan or search on metacpan
lib/Chandra/Form.pm view on Meta::CPAN
label => 'Email Address',
value => 'alice@example.com',
});
$form->textarea('bio', {
label => 'Biography',
rows => 4,
value => 'Hello world',
});
$form->select('theme', {
label => 'Theme',
options => [
{ value => 'light', label => 'Light' },
{ value => 'dark', label => 'Dark' },
{ value => 'auto', label => 'System' },
],
value => 'dark',
});
$form->checkbox('notify', {
label => 'Enable notifications',
checked => 1,
});
$form->radio('priority', {
label => 'Priority',
options => [
{ value => 'low', label => 'Low' },
{ value => 'medium', label => 'Medium' },
{ value => 'high', label => 'High' },
],
value => 'medium',
});
$form->number('font_size', {
label => 'Font Size',
min => 8,
max => 72,
step => 1,
value => 14,
});
$form->range('volume', {
label => 'Volume',
min => 0,
max => 100,
value => 75,
});
$form->hidden('csrf_token', { value => 'abc123' });
$form->submit('Save Settings');
# Render to HTML
my $html = $form->render;
=head1 DESCRIPTION
Chandra::Form provides form building helpers with automatic two-way
data binding between Perl and the DOM for Chandra desktop applications.
Forms are built by chaining field methods, then rendered to HTML via
C<render()>. When used with C<Chandra::App>, the generated JavaScript
handles form submission, change events, and value synchronization
through the Chandra bridge.
=head1 METHODS
=head2 new
my $form = Chandra::Form->new(
id => 'my-form', # optional, auto-generated if omitted
action => sub { ... }, # submit handler
class => 'custom-class', # additional CSS class
app => $app, # Chandra::App instance
);
Create a new form builder. The C<action> coderef receives a hashref of
form data when the form is submitted.
=head2 text
$form->text('username', {
label => 'Username',
placeholder => 'Enter name',
value => 'default',
required => 1,
maxlength => 100,
minlength => 3,
pattern => '[A-Za-z0-9]+',
disabled => 0,
readonly => 0,
autofocus => 1,
class => 'custom',
});
Add a text input field. All option keys are optional. Returns C<$self>
for chaining.
=head2 password
$form->password('pass', { label => 'Password', required => 1 });
Add a password input field. Same options as C<text()>.
=head2 email
$form->email('email', { label => 'Email', value => 'a@b.com' });
Add an email input field. Same options as C<text()>.
=head2 textarea
$form->textarea('bio', {
label => 'Biography',
rows => 4,
cols => 60,
value => 'Hello',
});
( run in 0.581 second using v1.01-cache-2.11-cpan-df04353d9ac )