Skip to content

Instantly share code, notes, and snippets.

@jhannah
Created February 26, 2011 02:16
Show Gist options
  • Select an option

  • Save jhannah/844863 to your computer and use it in GitHub Desktop.

Select an option

Save jhannah/844863 to your computer and use it in GitHub Desktop.
Form::Sensible set_selection()
In the Controller...
my $choose1 = Form::Sensible->create_form({
name => 'choose_group',
fields => [
{
field_class => 'Select',
name => 'which_group',
accepts_multiple => 0,
options_delegate => FSConnector( sub { $all_profile_groups } ),
display_name => 'Manage this group',
},
{
field_class => 'Trigger',
name => 'submit',
display_name => $submit_names{choose1},
},
],
});
later, in another chunk of controller code
if ($group_id) {
my $choose1 = $c->stash->{group}{forms}{choose1};
$choose1->field('which_group')->set_selection($group_id);
}
=============================================
$c->log->debug("JAY4 " . Dumper $choose1->field('which_group'));
[debug] JAY4 $VAR1 = bless( {
'value_delegate' => bless( {
'delegate_function' => sub { "DUMMY" }
}, 'Form::Sensible::DelegateConnection' ),
'values_ok_delegate' => bless( {
'delegate_function' => sub { "DUMMY" }
}, 'Form::Sensible::DelegateConnection' ),
'name' => 'which_group',
'validation' => {
'required' => 0
},
'display_name' => 'Manage this group',
'editable' => 1,
'accepts_multiple' => 0,
'options_delegate' => bless( {
'delegate_function' => sub { "DUMMY" }
}, 'Form::Sensible::DelegateConnection' )
}, 'Form::Sensible::Field::Select' );
=====================================
Full set of dumps
my $choose1 = $c->stash->{group}{forms}{choose1};
$c->log->debug("JAY0");
$c->log->debug(Dumper ($choose1));
$c->log->debug("JAY1 " . $choose1->field('which_group'));
$c->log->debug("JAY2 " . $choose1->field('which_group')->value);
$choose1->field('which_group')->set_selection($group_id);
$c->log->debug("JAY3 " . $choose1->field('which_group')->value);
$c->log->debug("JAY4 " . Dumper $choose1->field('which_group'));
$c->log->debug("JAY5 " . Dumper $choose1->field('which_group')->set_selection($group_id));
[debug] JAY0
[debug] $VAR1 = bless( {
'validation_delegate' => bless( {
'delegate_function' => sub { "DUMMY" }
}, 'Form::Sensible::DelegateConnection' ),
'validator_result' => bless( {
'error_fields' => {},
'missing_fields' => {}
}, 'Form::Sensible::Validator::Result' ),
'field_order' => [
'which_group',
'submit'
],
'should_process_field_delegate' => bless( {
'delegate_function' => sub { "DUMMY" }
}, 'Form::Sensible::DelegateConnection' ),
'name' => 'choose_group',
'validation' => {},
'_fields' => {
'which_group' => bless( {
'value_delegate' => bless( {
'delegate_function' => sub { "DUMMY" }
}, 'Form::Sensible::DelegateConnection' ),
'values_ok_delegate' => bless( {
'delegate_function' => sub { "DUMMY" }
}, 'Form::Sensible::DelegateConnection' ),
'name' => 'which_group',
'validation' => {
'required' => 0
},
'display_name' => 'Manage this group',
'editable' => 1,
'accepts_multiple' => 0,
'options_delegate' => bless( {
'delegate_function' => sub { "DUMMY" }
}, 'Form::Sensible::DelegateConnection' )
}, 'Form::Sensible::Field::Select' ),
'submit' => bless( {
'validation_delegate' => bless( {
'delegate_function' => sub { "DUMMY" }
}, 'Form::Sensible::DelegateConnection' ),
'value_delegate' => bless( {
'delegate_function' => sub { "DUMMY" }
}, 'Form::Sensible::DelegateConnection' ),
'accepts_multiple' => 0,
'editable' => 1,
'name' => 'submit',
'validation' => {
'required' => 0
},
'display_name' => 'Show Group Contents'
}, 'Form::Sensible::Field::Trigger' )
}
}, 'Form::Sensible::Form' );
[debug] JAY1 Form::Sensible::Field::Select=HASH(0xb363590)
[debug] JAY2 25
[debug] JAY3 25
[debug] JAY4 $VAR1 = bless( {
'value_delegate' => bless( {
'delegate_function' => sub { "DUMMY" }
}, 'Form::Sensible::DelegateConnection' ),
'values_ok_delegate' => bless( {
'delegate_function' => sub { "DUMMY" }
}, 'Form::Sensible::DelegateConnection' ),
'name' => 'which_group',
'validation' => {
'required' => 0
},
'display_name' => 'Manage this group',
'editable' => 1,
'accepts_multiple' => 0,
'options_delegate' => bless( {
'delegate_function' => sub { "DUMMY" }
}, 'Form::Sensible::DelegateConnection' )
}, 'Form::Sensible::Field::Select' );
[debug] JAY5 $VAR1 = '25';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment