1# Module of TWiki Enterprise Collaboration Platform, http://TWiki.org/ 2# 3# Copyright (C) 2001-2018 Peter Thoeny, peter[at]thoeny.org 4# and TWiki Contributors. All Rights Reserved. TWiki Contributors 5# are listed in the AUTHORS file in the root of this distribution. 6# NOTE: Please extend that file, not this notice. 7# 8# Additional copyrights apply to some or all of the code in this 9# file as follows: 10# 11# This program is free software; you can redistribute it and/or 12# modify it under the terms of the GNU General Public License 13# as published by the Free Software Foundation; either version 3 14# of the License, or (at your option) any later version. For 15# more details read LICENSE in the root of this distribution. 16# 17# This program is distributed in the hope that it will be useful, 18# but WITHOUT ANY WARRANTY; without even the implied warranty of 19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20# 21# As per the GPL, removal of this notice is prohibited. 22 23package TWiki::Form::Text; 24use base 'TWiki::Form::FieldDefinition'; 25 26use strict; 27 28my @allowedAttributes = ( 29 'autocomplete', 'form', 'id', 'max', 'maxlength', 'min', 'onblur', 'onfocus', 30 'onchange', 'onselect', 'onmouseover', 'onmouseout', 'pattern', 'placeholder', 31 'spellcheck', 'style', 'tabindex', 'title', 'translate' 32 ); 33 34sub new { 35 my $class = shift; 36 my $this = $class->SUPER::new( @_ ); 37 my $size = $this->{size} || ''; 38 $size =~ s/\D//g; 39 $size = 10 if( !$size || $size < 1 ); 40 $this->{size} = $size; 41 return $this; 42} 43 44sub renderForEdit { 45 my( $this, $web, $topic, $value ) = @_; 46 47 my $classes = $this->cssClasses('twikiInputField', 'twikiEditFormTextField'); 48 my $val = $this->{parameters}{class}; 49 $classes .= ' ' . $val if( defined $val ); 50 51 my $textParams = { 52 -class => $classes, 53 -name => $this->{name}, 54 -size => $this->{size}, 55 -value => $value, 56 }; 57 foreach my $attr ( @allowedAttributes ) { 58 $val = $this->{parameters}{$attr}; 59 $textParams->{$attr} = $val if( defined $val ); 60 } 61 return ( '', CGI::textfield( $textParams ) ); 62} 63 641; 65