Created
July 25, 2017 15:38
-
-
Save petitchevalroux/e39bb59d8e8416037f3b96e35a144b22 to your computer and use it in GitHub Desktop.
Admin-on-rest : ReferenceInputRequired on create
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
import {ReferenceInputRequired} from './ReferenceInputRequired'; | |
export const ProductCreate = (props) => ( | |
<Create {...props}> | |
<SimpleForm> | |
<TextInput source="name" /> | |
<ReferenceInputRequired label="Brand" source="brandId" reference="brands"> | |
<SelectInput optionText="name"/> | |
</ReferenceInputRequired> | |
</SimpleForm> | |
</Create> | |
); |
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
import {ReferenceInput} from 'admin-on-rest'; | |
export class ReferenceInputRequired extends ReferenceInput { | |
}; | |
ReferenceInputRequired.defaultProps = Object.assign({}, ReferenceInput.defaultProps); | |
ReferenceInputRequired.defaultProps.allowEmpty = true; | |
ReferenceInputRequired.defaultProps.validate = (value, _, props) => { | |
if (!value) { | |
return [props.translate("aor.validation.required")]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment