Home

Awesome

Float label field Titanium Alloy

This module for Appcelerator Titanium wraps JVFloatLabeledTextField for iOS (TODO: Android).

Preview

Credits for the concept to Matt D. Smith (@mds), and his original design:

Matt D. Smith's Design Credits for the iOS implementation to @jverdi.

Quick Start

Get it gitTio

Download this repository or one release and install it:

<module platform="ios">ts.floatlabelfield</module>

Use it

<!-- TextField -->
<Module module="ts.floatlabelfield" method="createTextFieldView" id="floatField" />
<!-- TextView -->
<Module module="ts.floatlabelfield" method="createTextViewView" id="floatView" />

Which create a reference in your controller, accessible via: $.floadField

var floatlabelfield = require('ts.floatlabelfield').createTextFieldView({ _[PARAMS]_ );
var floatlabelview = require('ts.floatlabelfield').createTextFieldView({ _[PARAMS]_ );

Example:

var flf = require('ts.floatlabelfield');

// open a single window
var win = Ti.UI.createWindow({
    backgroundColor:'white',
    layout: 'vertical'
});

var floatlabelfield = flf.createTextFieldView({
    height: Ti.UI.SIZE,
    width: Ti.UI.SIZE,
    top: 150,
    fontSize: '18dp',
    textColor: '#2c3e50',
    placeholderTextColor: '#8d8d8d',
    placeholderText: "short description",
    floatingLabelFontSize: '12dp',
    floatingLabelTextColor: "#2980b9",
    debug: false
});
win.add(floatlabelfield);

var floatlabelview = flf.createTextViewView({
    height: 150,
    width: 150,
    top: 50,
    fontSize: '10dp',
    textColor: '#2c3e50',
    placeholderTextColor: '#bdc3c7',
    placeholderText: "short description",
    floatingLabelFontSize: '7dp',
    floatingLabelTextColor: "#2980b9",
    debug: false
});
win.add(floatlabelview);
win.open();

Documentation

Properties

You can pass properties during initialization or later:

ParameterTypeDescription
fontSizeintSize of all texts inside field
textColorStringColor of written text inside field
placeholderTextColorStringColor of placeholder text inside field
placeholderTextStringPlaceholder text value
floatingLabelFontSizeintSize of the floating label above field
floatingLabelTextColorStringColor of the floating label above field
valueStringValue of the field (user input)
debugBoolSwitch module logging on with debug: true

Public methods

Here is a list of all accessible methods and the associated expected behaviour:

MethodDescription
setFontSizeSet fontSize property
setTextColorSet textColor property
setPlaceholderTextColorSet placeholderTextColor property
setPlaceholderTextSet placeholderText property
setFloatingLabelFontSizeSet floatingLabelFontSize property
setFloatingLabelTextColorSet floatingLabelTextColor property
setValueSet field's value
MethodDescription
getValueReturns field's value

Events

You can listen for events by simply adding an event listener:

<Module module="ts.floatlabelfield" method="createTextFieldView" id="floatField" onChange="onFieldChange" />
$.floatField.addEventListener("change", onFieldChange);

You can now bind the change listener in your controller:

function onFieldChange(e) {
    Ti.API.info('Field value changed for ' + e.value);
}

Supported events

Here is a list of all supported events and the associated expected behaviour:

EventDescription
changeTriggers when user changes field's value. Contains value.

TODO / Ideas for improvement

Feel free to improve this widget by forking, submitting pull requests or creating issues.
Here are my ideas:

Changelog

Dependencies

Licences

JVFloatLabeledTextField is licensed under the MIT license.

Appcelerator, Appcelerator Titanium and associated marks and logos are trademarks of Appcelerator, Inc.
Titanium is Copyright (c) 2008-2015 by Appcelerator, Inc. All Rights Reserved.
Titanium is licensed under the Apache Public License (Version 2).