Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private validateField = ( value: string, props: ValidatedInput.Props ) => {
const emptyButMandatory = !isNotEmpty(value) && !!props.mandatory
const noMatchRegex = props.regex ? !props.regex.test( value ) : false
const invalid = props.validate ? !props.validate( value ) : false
if ( !props.disabled ) {
this.setState( {
invalidInput: emptyButMandatory || noMatchRegex || invalid
}, () => {
props.handleFieldChange( value, props.name, this.state.invalidInput )
} )
}
}
private renderMultiSelectInput = ( field: WrappedFieldProps ) => {
const { label, options, disabled, help, containerClass, inputClass, collapseErrorSpace, fieldLineHeight } = this.props
const { input, meta } = field
const extendedStyle: React.CSSProperties = this.getExtendedStyle( fieldLineHeight, input.value )
const selectValue: string[] = isNotEmpty( input.value ) ? ( input.value as string ).split( ',' ) : []
let choices = options.map( ( choice, idx ) => {
let option = choice.label.trim()
return (
<li> v.trim() === option ) !== -1 } )}>
<a href="#"> this.selectOption( e, field, selectValue, option )}>
{option}
</a>
</li>
)
} )
return (
private createNode = () => {
let { editedNode, wordings } = this.state
let errors: string[] = []
if ( isNotEmpty( editedNode.elementName ) ) {
if ( this.state.selectedNode.data.childNames.indexOf( editedNode.elementName ) !== -1 ) {
errors.push( wordings.invalidUniqueNodeName )
}
}
else {
errors.push( wordings.name )
}
if ( !isNotEmpty( editedNode.description ) ) {
errors.push( wordings.description )
}
for ( const key in editedNode.propertiesMap ) {
if ( !key ) {
errors.push( wordings.propertiesKey )
}
}
if ( errors.length > 0 ) {
this.props.displayEmptyValsError( errors )
}
else {
this.props.createNode( editedNode.parentId, editedNode.elementName.trim(), editedNode.description, editedNode.propertiesMap )
this.clearForm()
}
export function validateName( value: string, id: Id, items: ServiceItemFacades, locale: string ): string {
const wordings: { [id: string]: string } = compileWordings( MULTILANGUAGE_WORDINGS, locale )
if ( !isNotEmpty( value ) ) return wordings.fieldRequired
if ( value !== id.name && !isIdUnique( items, { name: value, appKey: id.appKey } ) )
return wordings.nameAlreadyExist
if ( value.includes( '.' ) ) return wordings.nameNoDot
}
private editNode = () => {
let { editedNode, wordings } = this.state
let errors: string[] = []
if ( !isNotEmpty( editedNode.elementName ) ) {
errors.push( wordings.name )
}
if ( !isNotEmpty( editedNode.description ) ) {
errors.push( wordings.description )
}
for ( const key in editedNode.propertiesMap ) {
if ( !key ) {
errors.push( wordings.propertiesKey )
}
}
if ( errors.length > 0 ) {
this.props.displayEmptyValsError( errors )
}
else {
constructor( props: TypeaheadInput.Props ) {
super( props )
this.state = {
typeaheadInputId: `#${this.props.id}_typeahead`,
shouldDisplayDropdown: isNotEmpty( props.selectedCollectionType ) && !!props.collectionTypes && !!props.setCollectionType
}
}
export const required = ( value: string, locale: string ) => isNotEmpty( value ) ? undefined : error( 'fieldRequired', locale )
private createNode = () => {
let { editedNode, wordings } = this.state
let errors: string[] = []
if ( isNotEmpty( editedNode.elementName ) ) {
if ( this.state.selectedNode.data.childNames.indexOf( editedNode.elementName ) !== -1 ) {
errors.push( wordings.invalidUniqueNodeName )
}
}
else {
errors.push( wordings.name )
}
if ( !isNotEmpty( editedNode.description ) ) {
errors.push( wordings.description )
}
for ( const key in editedNode.propertiesMap ) {
if ( !key ) {
errors.push( wordings.propertiesKey )
}