Permalink
Browse files

feat: 输入组件支持placeholder属性

  • Loading branch information...
LiuYueKai committed Mar 14, 2017
1 parent 02091e7 commit 9d67ed073d91348be976cda324d9d2b690acbdbf
Showing with 41 additions and 18 deletions.
  1. +4 −1 src/keroa-datetimepicker.js
  2. +4 −1 src/keroa-float.js
  3. +3 −0 src/keroa-integer.js
  4. +9 −6 src/keroa-string.js
  5. +21 −10 src/keroa-textarea.js
@@ -108,6 +108,9 @@ var DateTimeAdapter = BaseAdapter.extend({
this._span = this.element.querySelector("span");
this.element = this.element.querySelector("input");
this.element.setAttribute('readonly','readonly');
+ var placeholder = this.options['placeholder']
+ if (placeholder)
+ this.element.placeholder = placeholder;
if (this._span){
on(this._span, 'click', function(e){
self.element.focus();
@@ -120,7 +123,7 @@ var DateTimeAdapter = BaseAdapter.extend({
$(this.element).mobiscroll().datetime(this.op);
}
}else{
- this.comp = new DateTimePicker({el:this.element,format:this.maskerMeta.format,showFix:this.options.showFix,beforeValueChangeFun:this.beforeValueChangeFun});
+ this.comp = new DateTimePicker({el:this.element,placeholder:this.options.placeholder,format:this.maskerMeta.format,showFix:this.options.showFix,beforeValueChangeFun:this.beforeValueChangeFun});
}
this.element['u.DateTimePicker'] = this.comp;
View
@@ -26,6 +26,9 @@ var FloatAdapter = BaseAdapter.extend({
this.maskerMeta.precision = this.getOption('precision') || this.maskerMeta.precision;
this.max = this.getOption('max') ;
this.min = this.getOption('min') ;
+ var placeholder = this.options['placeholder']
+ if (placeholder)
+ this.element.placeholder = placeholder;
//如果max为false并且不为0
if(!this.max && this.max !== 0) {
this.max = "10000000000000000000";
@@ -129,7 +132,7 @@ var FloatAdapter = BaseAdapter.extend({
this.setShowValue(this.showValue)
},
-
+
onFocusin: function () {
var v = this.getValue(), vstr = v + '', focusValue = v;
if (isNumber(v) && isNumber(this.maskerMeta.precision)) {
View
@@ -20,6 +20,9 @@ var IntegerAdapter = BaseAdapter.extend({
if (!this.element) {
throw new Error('not found INPUT element, u-meta:' + JSON.stringify(this.options));
};
+ var placeholder = this.options['placeholder']
+ if (placeholder)
+ this.element.placeholder = placeholder;
this.maskerMeta = core.getMaskerMeta('integer') || {};
this.validType = this.options['validType'] || 'integer';
this.maskerMeta.precision = this.getOption('precision') || this.maskerMeta.precision;
View
@@ -18,16 +18,19 @@ var StringAdapter = BaseAdapter.extend({
this.validType = this.options['validType'] || 'string';
this.minLength = this.getOption('minLength');
this.maxLength = this.getOption('maxLength');
+ var placeholder = this.options['placeholder']
+ if (placeholder)
+ this.element.placeholder = placeholder;
on(this.element, 'focus', function(){
if(self.enable){
self.setShowValue(self.getValue())
try{
- var e = event.srcElement;
- var r = e.createTextRange();
- r.moveStart('character',e.value.length);
- r.collapse(true);
- r.select();
+ var e = event.srcElement;
+ var r = e.createTextRange();
+ r.moveStart('character',e.value.length);
+ r.collapse(true);
+ r.select();
}catch(e){
}
}
@@ -69,5 +72,5 @@ compMgr.addDataAdapter({
name: 'string'
});
-
+
export {StringAdapter};
View
@@ -4,35 +4,46 @@
* Date : 2016-08-10 12:40:46
*/
-import {BaseAdapter} from './keroa-baseAdapter';
-import {on} from 'tinper-sparrow/src/event';
-import {compMgr} from 'compox/src/compMgr';
+import {
+ BaseAdapter
+} from './keroa-baseAdapter';
+import {
+ on
+} from 'tinper-sparrow/src/event';
+import {
+ compMgr
+} from 'compox/src/compMgr';
var TextAreaAdapter = BaseAdapter.extend({
- init: function () {
+ init: function() {
var self = this;
this.element = this.element.nodeName === 'TEXTAREA' ? this.element : this.element.querySelector('textarea');
- if (!this.element){
+ if (!this.element) {
throw new Error('not found TEXTAREA element, u-meta:' + JSON.stringify(this.options));
};
+ var placeholder = this.options['placeholder']
+ if (placeholder)
+ this.element.placeholder = placeholder;
- on(this.element, 'focus', function () {
+ on(this.element, 'focus', function() {
self.setShowValue(self.getValue())
});
- on(this.element, 'blur', function () {
+ on(this.element, 'blur', function() {
self.setValue(self.element.value)
})
}
});
compMgr.addDataAdapter({
- adapter: TextAreaAdapter,
- name: 'textarea'
+ adapter: TextAreaAdapter,
+ name: 'textarea'
});
compMgr.addDataAdapter({
adapter: TextAreaAdapter,
name: 'u-textarea'
});
-export {TextAreaAdapter};
+export {
+ TextAreaAdapter
+};

0 comments on commit 9d67ed0

Please sign in to comment.