-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
externalized common code and fixed revalidation for expense type type…
…ahead
- Loading branch information
Michael Mueller
committed
Jan 20, 2017
1 parent
d9e17f7
commit aa45b0b
Showing
4 changed files
with
52 additions
and
74 deletions.
There are no files selected for viewing
Empty file.
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as ReactDOM from 'react-dom' | ||
|
||
export function addFormValidation(inputs: any[], revalidate: (input: any) => void) { | ||
for (let input of inputs) { | ||
input.addEventListener('input', event => revalidate(event.target)) | ||
|
||
input.addEventListener('invalid', (event) => { | ||
const input: any = event.target; | ||
input.closest('.form-group').classList.add('has-error') | ||
}) | ||
} | ||
} | ||
|
||
export function resetFormValidationErrors(inputs: any[]) { | ||
inputs.forEach(input => input.closest('.form-group') !.classList.remove('has-error')) | ||
} | ||
|
||
export function getInputs(component) { | ||
return [...ReactDOM.findDOMNode(component).querySelectorAll('input,textarea')] | ||
} | ||
|
||
export function revalidateInput(input: any) { | ||
input.closest('.form-group').classList.remove('has-error') | ||
setTimeout(() => input.checkValidity()) | ||
} | ||
|
||
export function enableTypeaheadFeatures(typeahead: any, name: string, required: boolean) { | ||
const typeaheadInput = | ||
ReactDOM.findDOMNode(typeahead.getInstance()).querySelector(`input[name=${name}]`) | ||
typeaheadInput.setAttribute('id', name) | ||
|
||
if (required) { | ||
typeaheadInput.setAttribute('required', 'true') | ||
} | ||
} |
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