2014-04-26 26 views
3

當創建一個InputSurface時,我無法獲得各種屬性的工作,如自動對焦或maxLength。屬性與famo.us

this.email = new InputSurface({ 
     classes: ['login-form'], 
     content: '', 
     size: [300, 40], 
     placeholder:'email', 
     properties: { 
      autofocus:'autofocus', 
      maxLength:'5', 
      textAlign: 'left' 
     } 
    }); 

呈現的div缺少我設置的屬性。

<input class="famous-surface login-form" placeholder="email" type="text" name="" style="-webkit-transform-origin: 0% 0%; opacity: 0.999999; -webkit-transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 614.5, 273.5, 0, 1); text-align: left; width: 300px; height: 40px;"> 

顯然,對於5個電子郵件一個最大長度是愚蠢的,但我只是想看看它是否會工作,但我可以繼續遠遠超過5錄入,當表面呈現,它不集中。有任何想法嗎?我查看了示例/演示,但找不到使用這些屬性的任何一個或者自動聚焦的輸入表面。

回答

3

屬性對象僅用於CSS屬性,不適用於HTML屬性,例如maxLength和autoFocus。 Famo.us即將支持通用屬性,目前inputSurface僅支持佔位符,值,類型和名稱。

+0

好的,謝謝。現在黑客將最適合我,因爲我需要maxLength和自動對焦工作,這似乎不可能與CSS /屬性。 – sday

8

正如dmvaldman所建議的那樣,這還不是一個功能,所以下面的hack將使它成爲一個功能。

顯然不是一個長期的解決方案,但我在InputSurface.js中添加了幾行,現在屬性被佔用了。

首先我增加了單線分配_attributes

function InputSurface(options) { 
    this._placeholder = options.placeholder || ''; 
    this._value  = options.value || ''; 
    this._type  = options.type || 'text'; 
    this._name  = options.name || ''; 
    this._attributes = options.attributes || ''; 

    Surface.apply(this, arguments); 
    this.on('click', this.focus.bind(this)); 
} 

然後,我添加for循環消耗部分部署。

InputSurface.prototype.deploy = function deploy(target) { 
    if (this._placeholder !== '') target.placeholder = this._placeholder; 
    target.value = this._value; 
    target.type = this._type; 
    target.name = this._name; 

    for (var n in this._attributes) { 
     target[n] = this._attributes[n]; 
    } 
}; 

所以現在我可以做到以下幾點:

this.email = new InputSurface({ 
     classes: ['login-form'], 
     content: '', 
     size: [300, 40], 
     placeholder:'email', 
     attributes: { 
      autofocus:'autofocus', 
      maxLength:5 
     } 
    }); 

我再次意識到修改核心代碼是不是一個長期的解決方案,我只是需要的東西,現在,直到有人具有「官方「的答案,這將對我有用。