[jifty-devel] Radio button and Ajax
benchiheub
jamalle.benchiheub at univ-metz.fr
Mon Nov 6 10:58:02 EST 2006
Hi.
I use Jifty since a few days.
But i have some difficulties to use Ajax and button radio. In Fact i
would like to show an input field after i click on the right option. I
suppose i must use PageRegion but i don't manage to refresh the region.
Thanks for help.
My entry.html
<%init>
my $action = Jifty->web->new_action( class => 'Entry',moniker =>
'post_entry');
</%init>
<&|/_elements/wrapper, title => "Post your Entry" &>
<%Jifty->web->form->start()%>
<%$action->form_field('adresse')%>
<%$action->form_field('ville')%>
<%$action->form_field('fonction')%>
<%Jifty->web->region(name => 'autre',
path => 'fonction.comp',
)%>
<%Jifty->web->form->submit(label => 'Vas y')%>
<%Jifty->web->form->end()%>
</&>
My fonction.comp
<%args>
$fonction=>""
</%args>
<%init>
my $action=Jifty->web->new_action(class => "EntryAutre",moniker =>
"entry_autre");
</%init>
% if ($fonction=~/Autre/i) {
<%$action->form_field('autre')%>
% }
My Entry.pm
use strict;
use warnings;
=head1 NAME
Cpu::Action::Entry
=cut
package Cpu::Action::Entry;
use base qw/Cpu::Action Jifty::Action/;
use Jifty::Param::Schema;
use Jifty::Action schema {
param adresse =>
label is 'Adresse',
is mandatory;
param ville =>
label is 'Categorie';
param fonction =>
label is 'Fonction',
ajax validates,
render as 'radio',
valid are qw ( Président Directeur Vice-Pdt Autre );
param corps =>
label is 'Corps',
render as 'Textarea';
=head2 take_action
=cut
sub validate_fonction {
my $self=shift;
my $fonction=shift;
if ($fonction=~/Autre/)
{
return $self->validation_error( fonction => 'Saisir
votre fonction'); }
return $self->validation_ok('fonction');
}
=head2 report_success
=cut
sub take_action {
my $self = shift;
# Custom action code
$self->report_success if not $self->result->failure;
return 1;=cut
sub report_success {
my $self = shift;
# Your success message here
$self->result->message('Success');
}
1;
--
Jamalle BENCHIHEUB
Université Paul Verlaine-Metz
Centre de ressources informatiques
Tel : 03 87 54 70 85
More information about the jifty-devel
mailing list