-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new GrowingFormFieldType TEXTAREA #9
Open
caspahouzer
wants to merge
7
commits into
lambus-platform:master
Choose a base branch
from
caspahouzer:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+111
−41
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6cebff7
Update package.json
caspahouzer 9cc2e95
Update index.js
caspahouzer bba5fb8
Update index.js
caspahouzer 9685c0b
Update index.js
caspahouzer 8d54a20
Update README.md
caspahouzer f8a730a
Update index.js
caspahouzer 0380ea8
Merge branch 'lambus-platform:master' into master
caspahouzer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,11 +165,8 @@ class GrowingForm { | |
} | ||
|
||
// If the last element was a text-field, blur it! | ||
if (( | ||
this.cells[this.expandedIndex].type === GrowingFormFieldType.TEXT | ||
|| this.cells[this.expandedIndex].type === GrowingFormFieldType.EMAIL | ||
|| this.cells[this.expandedIndex].type === GrowingFormFieldType.NUMBER | ||
) && this.currentTextField) { | ||
if ((this.cells[this.expandedIndex].type === GrowingFormFieldType.TEXT | ||
|| this.cells[this.expandedIndex].type === GrowingFormFieldType.TEXTAREA) && this.currentTextField) { | ||
this.currentTextField.blur(); | ||
} | ||
if (this.callbacks[GrowingFormEvent.SUBMIT]) { | ||
|
@@ -218,6 +215,9 @@ class GrowingForm { | |
let textField; | ||
let actionButton; | ||
|
||
const actionButtonOpacityValid = 1.0; | ||
const actionButtonOpacityInvalid = 0.3; | ||
|
||
// The container view holds both the content-view and bullets | ||
const containerView = Ti.UI.createView({ | ||
height: Ti.UI.SIZE, | ||
|
@@ -236,30 +236,37 @@ class GrowingForm { | |
|
||
contentView.add(this._createTitleLabel(cell, itemIndex)); | ||
|
||
const validation = isValid => { | ||
this.formData[cell.identifier] = textField.value; | ||
|
||
// If we use live-validation, do not update our UI so far | ||
if (cell.validate === GrowingFormValidationRule.LIVE) { | ||
const throttle = cell.throttle; | ||
if (!throttle || typeof throttle !== 'function') { | ||
throw new FormError('using live validation without padding \'throttle\' method'); | ||
} | ||
throttle(textField, actionButton); | ||
return; | ||
} | ||
|
||
actionButton.opacity = isValid ? actionButtonOpacityValid : actionButtonOpacityInvalid; | ||
actionButton.enabled = isValid; | ||
} | ||
|
||
// Only add content if expanded | ||
if (isExpanded) { | ||
switch (type) { | ||
case GrowingFormFieldType.TEXT: | ||
case GrowingFormFieldType.EMAIL: | ||
case GrowingFormFieldType.NUMBER: { | ||
case GrowingFormFieldType.TEXTAREA: | ||
textField = this._createTextArea({ | ||
cell: cell, | ||
onChange: validation | ||
}); | ||
contentView.add(textField); | ||
break; | ||
case GrowingFormFieldType.TEXT: { | ||
textField = this._createTextField({ | ||
cell: cell, | ||
onChange: isValid => { | ||
this.formData[cell.identifier] = textField.value; | ||
|
||
// If we use live-validation, do not update our UI so far | ||
if (cell.validate === GrowingFormValidationRule.LIVE) { | ||
const throttle = cell.throttle; | ||
if (!throttle || typeof throttle !== 'function') { | ||
throw new FormError('using live validation without padding \'throttle\' method'); | ||
} | ||
throttle(textField, actionButton); | ||
return; | ||
} | ||
|
||
actionButton.opacity = isValid ? 1.0 : 0.3; | ||
actionButton.enabled = isValid; | ||
} | ||
onChange: validation | ||
}); | ||
contentView.add(textField); | ||
break; | ||
|
@@ -351,13 +358,60 @@ class GrowingForm { | |
const cell = this.cells[this.expandedIndex]; | ||
const value = this.formData[cell.identifier]; | ||
|
||
if (this.cells[this.expandedIndex].type === GrowingFormFieldType.TEXT | ||
|| this.cells[this.expandedIndex].type === GrowingFormFieldType.TEXTAREA) { | ||
if (this.options.focusNexField === true) { | ||
setTimeout(() => { | ||
this.focus(); | ||
}, 200); | ||
} | ||
} | ||
|
||
this.callbacks[GrowingFormEvent.STEP](this.currentTextField, this.expandedIndex + 1, this._validateFromType(cell, value)); | ||
} | ||
|
||
this.expandedIndex++; | ||
this._configureData(); | ||
} | ||
|
||
_createTextArea(args) { | ||
const cell = args.cell; | ||
const onChangeCallback = args.onChange; | ||
const identifier = cell.identifier; | ||
const validate = cell.validate; | ||
const options = cell.options || {}; | ||
|
||
const textArea = Ti.UI.createTextArea({ | ||
id: identifier, | ||
top: 8, | ||
left: 0, | ||
width: 280, | ||
height: 120, | ||
color: '#000', | ||
hintTextColor: '#bebebe', | ||
padding: { left: 5, right: 5, top: 5, bottom: 5 }, | ||
borderRadius: 4, | ||
backgroundColor: '#eee', | ||
value: this.formData[identifier] || '' | ||
}); | ||
|
||
// Reference a reference in our scope to blur it, if it is the last form input | ||
this.currentTextField = textArea; | ||
textArea.applyProperties(options); | ||
|
||
textArea.addEventListener('change', event => { | ||
const value = event.value; | ||
|
||
// Check if we have a validator | ||
if (validate !== undefined) { | ||
const isValid = this._validateFromType(cell, value); | ||
onChangeCallback(isValid); | ||
} | ||
}); | ||
|
||
return textArea; | ||
} | ||
|
||
_createTextField(args) { | ||
const cell = args.cell; | ||
const onChangeCallback = args.onChange; | ||
|
@@ -366,6 +420,7 @@ class GrowingForm { | |
const options = cell.options || {}; | ||
|
||
const textField = Ti.UI.createTextField({ | ||
id: identifier, | ||
top: 8, | ||
left: 0, | ||
width: 280, | ||
|
@@ -378,19 +433,6 @@ class GrowingForm { | |
value: this.formData[identifier] || '' | ||
}); | ||
|
||
switch (cell.type) { | ||
case GrowingFormFieldType.NUMBER: | ||
textField.keyboardType = Ti.UI.KEYBOARD_TYPE_NUMBER_PAD; | ||
break; | ||
case GrowingFormFieldType.EMAIL: | ||
textField.autocapitalization = Ti.UI.TEXT_AUTOCAPITALIZATION_NONE | ||
textField.keyboardType = Ti.UI.KEYBOARD_TYPE_EMAIL; | ||
break; | ||
default: | ||
textField.keyboardType = Ti.UI.KEYBOARD_TYPE_DEFAULT; | ||
break; | ||
} | ||
|
||
// Reference a reference in our scope to blur it, if it is the last form input | ||
this.currentTextField = textField; | ||
textField.applyProperties(options); | ||
|
@@ -405,6 +447,21 @@ class GrowingForm { | |
} | ||
}); | ||
|
||
textField.addEventListener('return', event => { | ||
const value = event.value; | ||
|
||
// Check if we have a validator | ||
if (validate !== undefined) { | ||
const isValid = this._validateFromType(cell, value); | ||
console.log('isValid', isValid); | ||
if (isValid === true) { | ||
this._selectNextCell(); | ||
} | ||
return; | ||
} | ||
this._selectNextCell(); | ||
}); | ||
|
||
return textField; | ||
} | ||
|
||
|
@@ -524,8 +581,7 @@ class GrowingForm { | |
|
||
const GrowingFormFieldType = { | ||
TEXT: 'text', | ||
EMAIL: 'email', | ||
NUMBER: 'number', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this removed? |
||
TEXTAREA: 'textArea', | ||
CHECKBOX: 'checkbox', | ||
DROPDOWN: 'dropdown' | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore all references to existing field types