[jifty-devel] Default view and create/update versions of Select
widget not consistent
Frederic BLANC
jifty-ml at blaf.org
Sun May 14 20:43:30 EDT 2006
Hello,
My app uses some columns that refers_to other table, and I find that
the default rendering of such column is inconsistent between update/create
modes and the read one:
the update/create versions use a select field that displays values of
the name column of the target table (of the name method if exists, the id
otherwise) whereas the "view" version uses the default render_value method
of Field.pm, and thus displays the id of the target row (which is not
the expected result IMHO.)
In attachment is a patch that adds a render_value method to the Select widget
to display the name (when it exists) instead of the id of the target row.
The second attachment is a patch for the Checkbox widget as I think
a checbox checked accordingly the current_value is nicer than the raw value.
The third attachment is for the Password widget which has already
a render_value method but which returns '-' only, without rendering any HTML.
The patch modify this behaviour by rendering the instead of returning it.
Regards,
Frederic BLANC
-------------- next part --------------
Index: jifty/trunk/lib/Jifty/Web/Form/Field/Select.pm
===================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Field/Select.pm (revision 1039)
+++ jifty/trunk/lib/Jifty/Web/Form/Field/Select.pm (working copy)
@@ -33,4 +33,20 @@
'';
}
+sub render_value {
+ my $self = shift;
+ my $field = '<span';
+ $field .= qq! class="@{[ $self->classes ]}"> !;
+ my $value = $self->current_value;
+ if(defined $value) {
+ my @value = grep { $_->{value} eq $value }
+ @{ $self->action->available_values($self->name) };
+ $value = $value[0]->{display} if scalar @value;
+ }
+ $field .= HTML::Entities::encode_entities(_($value)) if defined $value;
+ $field .= qq!</span>\n!;
+ Jifty->web->out($field);
+ return '';
+}
+
1;
-------------- next part --------------
Index: jifty/trunk/lib/Jifty/Web/Form/Field/Checkbox.pm
===================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Field/Checkbox.pm (revision 1039)
+++ jifty/trunk/lib/Jifty/Web/Form/Field/Checkbox.pm (working copy)
@@ -41,6 +41,27 @@
'';
}
+=head2 render_value
+
+Renders value as a checkbox widget.
+
+=cut
+
+sub render_value {
+ my $self = shift;
+ my $field .= qq!<input type="checkbox"!;
+ $field .= qq! name="@{[ $self->input_name ]}"!;
+ $field .= qq! id="@{[ $self->element_id ]}"!;
+ $field .= qq! value="@{[$self->value ||1]}"!;
+ $field .= $self->_widget_class;
+ $field .= qq! checked="checked"! if ($self->checked or $self->current_value);
+ $field .= qq! disabled readonly!;
+ $field .= qq! />\n!;
+
+ Jifty->web->out($field);
+ return '';
+}
+
=head2 javascript_preempt
By default, javascript (such as onclick handlers) should not actually
-------------- next part --------------
Index: jifty/trunk/lib/Jifty/Web/Form/Field/Password.pm
===================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Field/Password.pm (revision 1039)
+++ jifty/trunk/lib/Jifty/Web/Form/Field/Password.pm (working copy)
@@ -40,7 +40,8 @@
sub render_value {
- return '-';
+ Jifty->web->out('-');
+ return '';
}
=head2 classes
More information about the jifty-devel
mailing list