MT#60553 handle API subscriber timezone field separately

* timezone field for SubscriberSubAdminAPI form is now Text
  instead of +NGCP::Panel::Field::TimezoneSelect because
  the template => 'helpers/datatables_field.tt' produces a field
  validation error, as well as the Field is designed for UI and not API.
* add validate_timezone() field validation to SubscriberAPI and
  SubscriberSubAdminAPI forms.

Change-Id: I6391694284477976d8d6cee71a81e2241bd94937
mr13.1
Kirill Solomko 1 year ago
parent d24d4c21c4
commit e83588874b

@ -235,6 +235,17 @@ has_block 'actions' => (
render_list => [qw/save/],
);
sub validate_timezone {
my ($self, $field) = @_;
my $c = $self->form->ctx;
return unless $c;
my $value = $field->value;
unless (NGCP::Panel::Utils::DateTime::is_valid_timezone_name($value, 0, $c, 1)) {
$field->add_error($c->loc('Invalid timezone name: '.$value));
}
}
# override parent here to prevent any password magic
sub update_fields {
#IMPORTANT! redefined sub update_fields with no super call disable call of the update_field_list and defaults methods
@ -254,7 +265,6 @@ sub update_fields {
return;
}
1;
# vim: set tabstop=4 expandtab:

@ -121,11 +121,11 @@ has_field 'status' => (
);
has_field 'timezone' => (
type => '+NGCP::Panel::Field::TimezoneSelect',
type => 'Text',
label => 'Timezone',
element_attr => {
rel => ['tooltip'],
title => ['The timezone of the subscriber.']
title => ['The timezone of the subscriber. See http://search.cpan.org/dist/DateTime-TimeZone/lib/DateTime/TimeZone/Catalog.pm for a full list of valid timezone names.']
},
);
#we need customer_id field in the form to don't delete customer_id from the resource as absent field during form validation
@ -324,6 +324,17 @@ sub validate_webpassword {
NGCP::Panel::Utils::Form::validate_password(c => $c, field => $field, utf8 => 0);
}
sub validate_timezone {
my ($self, $field) = @_;
my $c = $self->form->ctx;
return unless $c;
my $value = $field->value;
unless (NGCP::Panel::Utils::DateTime::is_valid_timezone_name($value, 0, $c, 1)) {
$field->add_error($c->loc('Invalid timezone name: '.$value));
}
}
sub update_fields {
#IMPORTANT! redefined sub update_fields with no super call disable call of the update_field_list and defaults methods
my ($self) = @_;

Loading…
Cancel
Save