Skip to content

Commit

Permalink
[add] add mixed props, default is false;
Browse files Browse the repository at this point in the history
  • Loading branch information
taoqili authored and veryStarters committed Nov 21, 2018
1 parent c8b7942 commit 331b949
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/TextareaFormField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,28 @@ class TextAreaFormField extends FormField {
}
});
if (element) {
const Count = React.cloneElement(element, {
length: me.state.value ? me.state.value.length : 0,
const mixed = element.props.mixed;
const value = me.state.value;
const len = value ? TextAreaFormField.getStringLen(value, mixed) : 0;
return React.cloneElement(element, {
length: len,
key: 'count',
});

return Count;
}
return null;
}

static getStringLen(string, mixed) {
let len = string.length;
if (!mixed) {
return len;
}
let reLen = 0;
for (let i = 0; i < len; i++) {
reLen += (string.charCodeAt(i) <= 128 ? 1 : 2)
}
return Math.ceil(reLen / 2);
}

renderField() {
const me = this;
Expand Down

0 comments on commit 331b949

Please sign in to comment.