Skip to content

Commit

Permalink
Character counter: maxlength attribute for optional enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
gyrus committed Apr 17, 2019
1 parent ae93ca4 commit 077ff85
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions includes/CMB2_Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,7 @@ protected function get_default_field_args( $args ) {
'char_counter' => false,
'char_max' => false,
'char_max_msg' => __( 'Your text may be truncated.', 'cmb2' ),
'char_max_enforce' => false
);
}

Expand Down
5 changes: 5 additions & 0 deletions includes/types/CMB2_Type_Textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public function render( $args = array() ) {
$a['class'] .= ' cmb2-count-chars';
endif;

// Enforce max chars?
if ( ! empty( $this->field->args['char_max_enforce'] ) && ! empty( $this->field->args['char_max'] ) ) :
$a['maxlength'] = (int) $this->field->args['char_max'];
endif;

return $this->rendered(
sprintf( '<textarea%s>%s</textarea>%s%s', $this->concat_attrs( $a, array( 'desc', 'value' ) ), $a['value'], $char_counter_markup, $a['desc'] )
);
Expand Down
6 changes: 3 additions & 3 deletions languages/cmb2.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ msgid ""
msgstr ""
"Project-Id-Version: CMB2 2.6.0\n"
"Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/cmb2\n"
"POT-Creation-Date: 2019-04-17 07:10:30+00:00\n"
"POT-Creation-Date: 2019-04-17 09:50:14+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: 2019-4-17 7:10+-60\n"
"PO-Revision-Date: 2019-4-17 9:50+-60\n"
"Last-Translator: CMB2 Team [email protected]\n"
"Language-Team: CMB2 Team [email protected]\n"
"X-Generator: grunt-wp-i18n 0.4.9\n"
Expand Down Expand Up @@ -411,7 +411,7 @@ msgstr ""
msgid "Your text may be truncated."
msgstr ""

#: includes/CMB2_Field.php:1566
#: includes/CMB2_Field.php:1567
msgid "Sorry, this field does not have a cmb_id specified."
msgstr ""

Expand Down

0 comments on commit 077ff85

Please sign in to comment.