a!localVariables( local!insert:false, local!update:false, a!formLayout( label: "Username", contents: { a!textField( label: "username", labelPosition: if( ri!readOnly, "ADJACENT", "ABOVE" ), value: ri!username.username, saveInto: ri!username.username, refreshAfter: "UNFOCUS", validations: { if( a!queryEntity( entity: cons!usernameConstant, query: a!query( fetchTotalCount: true, pagingInfo: a!pagingInfo( startIndex: 1, batchSize: 1 ), logicalexpression: a!queryLogicalExpression( operator:"OR", filters: { a!queryFilter( field: "username", operator: "=", value:(ri!username.username), applyWhen:not(isnull(ri!username.username)) ), } ) ) ).totalCount > 0, local!insert:true, local!update:true ), } ), a!textField( label: "gender", labelPosition: if( ri!readOnly, "ADJACENT", "ABOVE" ), value: ri!username.gender, saveInto: ri!username.gender, refreshAfter: "UNFOCUS", validations: {} ), a!columnsLayout( columns: { a!columnLayout( contents: { a!textField( label: "Password", labelPosition: if( ri!readOnly, "ADJACENT", "ABOVE" ), value: ri!username.password, saveInto: ri!username.password, characterLimit: 255, readOnly: ri!readOnly ) } ) } ), }, buttons: a!buttonLayout( primaryButtons: { a!buttonWidget( label: "Insert", saveInto:( a!writeToDataStoreEntity( dataStoreEntity: cons!usernameConstant, valueToStore:(ri!username) ), ), disabled:local!insert, submit: true, style: "PRIMARY", ), a!buttonWidget( label: "update", saveInto:( a!writeToDataStoreEntity( dataStoreEntity: cons!usernameConstant, valueToStore:ri!username, ), ), disabled:local!update, submit: true, style: "PRIMARY" ), a!buttonWidget( label: "delete", saveInto:( a!deleteFromDataStoreEntities( dataToDelete: { a!entityDataIdentifiers( entity: cons!usernameConstant, identifiers:{ri!username.username}, ) } ) ), submit: true, style: "PRIMARY" ) }, secondaryButtons: { a!buttonWidget( label: "Cancel", value: true, saveInto: ri!cancel, submit: true, style: "NORMAL", validate: false ) }, showWhen: or( isnull( ri!readOnly ), not( ri!readOnly ) ) ) ) )
For line 17 validation part nearby, i wish the button insert will not work if it find the duplicate username already in database, and disable update button for the username can't be found, that is what i put in the validation part of if condition sentences, however, it report error with "Expression evaluation error at function a!textField", then how can I do?
Discussion posts and replies are publicly visible
Hi immortalvirgil - You are trying to assign value in validation statement, hence the error. Try using below code and hopefully it should resolve your error.
validations: { if( or( a!queryEntity( entity: cons!usernameConstant, fetchtotalcount: true, query: a!query( /*fetchTotalCount: true,*/ pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 1), logicalexpression: a!queryLogicalExpression( ignoreFiltersWithEmptyValues: true, operator: "OR", filters: { a!queryFilter( field: "username", operator: "=", value: (ri!username.username) ), } ) ) ).totalCount > 0, isnull(ri!username.username) ), "Validation Message", {} ) }
i wish i can find a way to let the button being disable once found duplicate errors
Try below code:
a!formLayout( label: "Username", contents: { a!textField( label: "username", labelPosition: if(local!readOnly, "ADJACENT", "ABOVE"), value: ri!username.username, saveInto: { ri!username.username, a!save( local!totalCount, a!queryEntity( entity: cons!usernameConstant, fetchtotalcount: true, query: a!query( /*fetchTotalCount: true,*/ pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 1), logicalexpression: a!queryLogicalExpression( ignorefilterswithemptyvalues: true, operator: "OR", filters: { a!queryFilter( field: "name", operator: "=", value: (ri!username.username)/*applyWhen:not(isnull(ri!username.username)) */ ), } ) ) ).totalCount ) }, refreshAfter: "UNFOCUS", validations: { if( local!totalCount > 0, "Validation Message", {} ), } ) }, buttons: a!buttonLayout( primaryButtons: { a!buttonWidget( label: "Insert", saveInto: ( a!writeToDataStoreEntity( dataStoreEntity: cons!usernameConstant, valueToStore: (ri!username.username) ), ), disabled: local!totalCount>0, submit: true, style: "PRIMARY", )