153 lines
3.9 KiB
Perl
153 lines
3.9 KiB
Perl
=head1 NAME
|
|
|
|
Dam::Components::Controls::Input
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
my $input = Component__Get(CONTROL_INPUT, ['input']);
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
Control para introducir un texto.
|
|
|
|
=head1 ARGUMENTS
|
|
|
|
(
|
|
TYPE => 'Input',
|
|
ID => 'input' (default),
|
|
INFO => 1 (show info in header; default) or 0 (don't show),
|
|
LABEL => 'Enter text' (default),
|
|
LABEL_INFO => 'Input text' (default),
|
|
REQUIRED => 1 (control required; default) or 0 (not required)
|
|
ONLY => 'All' (allows any alphanumeric character; default) ó 'Digits'
|
|
(allow only numbers)
|
|
)
|
|
|
|
=cut
|
|
|
|
use strict;
|
|
use warnings;
|
|
use utf8;
|
|
|
|
package Dam::Components::Controls::Input;
|
|
|
|
use Exporter qw(import);
|
|
our @EXPORT = qw(
|
|
Control__html Control__js Get
|
|
);
|
|
|
|
use Dam::Util;
|
|
use Dam::DamLogic;
|
|
|
|
|
|
|
|
my $ID_DEFAULT = 'input';
|
|
|
|
|
|
|
|
sub __arguments {
|
|
my $arg_ref = shift;
|
|
|
|
check_arguments($arg_ref,
|
|
TYPE => [ ARG_REQUIRED ],
|
|
ID => [ ARG_DEFAULT, $ID_DEFAULT ],
|
|
INFO => [ ARG_DEFAULT, 1, 0 ],
|
|
LABEL => [ ARG_DEFAULT, _t('Enter text') ],
|
|
LABEL_INFO => [ ARG_DEFAULT, _t('Input text') ],
|
|
REQUIRED => [ ARG_DEFAULT, 1, 0 ],
|
|
ONLY => [ ARG_DEFAULT, 'All', 'Digits' ]
|
|
);
|
|
}
|
|
|
|
|
|
|
|
sub Control__html {
|
|
my ($self, $arg_ref, $info_ref) = @_;
|
|
|
|
__arguments($arg_ref);
|
|
|
|
my $input_value = cgiapp_param($$arg_ref{ID});
|
|
|
|
push(@{$info_ref}, { DATA => $$arg_ref{LABEL_INFO}, VALUE => $input_value }) if !is_empty($input_value);
|
|
|
|
return strval('
|
|
<div class="form-group form-group-', $ID_DEFAULT, '">
|
|
<label for="', $$arg_ref{ID}, $$arg_ref{REQUIRED} ? '" class="required">' : '">', $$arg_ref{LABEL}, '</label>
|
|
<div class="form-div form-control-', $ID_DEFAULT, '">
|
|
<input type="input" class="form-control input-lg" id="', $$arg_ref{ID}, '" name="', $$arg_ref{ID}, '"', !is_empty($input_value) ? strval(' value = "', $input_value, '"') : '', $$arg_ref{REQUIRED} ? ' required="required"' : '', ' />
|
|
</div>
|
|
</div>
|
|
');
|
|
}
|
|
|
|
|
|
|
|
sub Control__js {
|
|
my ($self, $arg_ref) = @_;
|
|
|
|
__arguments($arg_ref);
|
|
|
|
return is_eq($$arg_ref{ONLY}, 'Digits') ? strval('
|
|
$(function(){
|
|
$.fn.inputFilter = function(inputFilter) {
|
|
return this.on("input keydown keyup mousedown mouseup select contextmenu drop", function() {
|
|
if (inputFilter(this.value)) {
|
|
this.oldValue = this.value;
|
|
this.oldSelectionStart = this.selectionStart;
|
|
this.oldSelectionEnd = this.selectionEnd;
|
|
} else if (this.hasOwnProperty("oldValue")) {
|
|
this.value = this.oldValue;
|
|
this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
|
|
}
|
|
});
|
|
};
|
|
$("#', $$arg_ref{ID}, '").inputFilter(function(value) {
|
|
return /^\d*$/.test(value);
|
|
});
|
|
});
|
|
') : '';
|
|
}
|
|
|
|
|
|
|
|
sub Get {
|
|
my ($self, $id) = @_;
|
|
|
|
$id = $ID_DEFAULT if is_empty($id);
|
|
|
|
return cgiapp_param($id);
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
=head1 AUTHOR
|
|
|
|
Manuel Cillero C<< <manuel@cillero.es> >>
|
|
|
|
=head1 COPYRIGHT
|
|
|
|
The MIT License (MIT)
|
|
|
|
Copyright (c) 2004-2020 Manuel Cillero. All rights reserved.
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
|
|
=cut
|