react-admin: Unable to compile <PostEdit> (Parsing Error) - react-admin

I was following this react-admin tutorial.
In Adding Creation and Editing Capabilities section, I was asked to copy the <PostEdit> and paste the code (dumped by the console) in posts.js.
Below is the formatted code, but after I save it will return this error server error of PostEdit
import * as React from "react";
//import { List, Datagrid, TextField, ReferenceField } from 'react-admin';
import { List, Datagrid, TextField, ReferenceField, EditButton } from 'react-admin';
import {PostEdit} from 'react-admin'
export const PostList = props => (
<List {...props}>
<Datagrid>
<TextField source="id" />
<ReferenceField source="userId" reference="users">
<TextField source="name" />
</ReferenceField>
<TextField source="title" />
<EditButton />
</Datagrid>
</List>
);
//New Compnent copied from console
export const PostEdit = props => (
<Edit {...props}>
<SimpleForm>
<TextInput disabled source="id" />
<ReferenceInput source="userId" reference="users">
<SelectInput optionText="name" />
</ReferenceInput>
<TextInput source="title" />
<TextInput multiline source="body" />
</SimpleForm>
</Edit>
);

Related

Expect following JSON(mention in image) as output using react-admin framework

Below is the my code or react component:-
import { Box } from '#material-ui/core';
import React,{ useEffect, useState } from 'react'
import {
Create,
SimpleForm,
TextInput,
TextField,
ArrayInput,
SimpleShowLayout,
SimpleFormIterator,
RadioButtonGroupInput,TopToolbar
} from 'react-admin'
import "../index.css"
const JobCreate = (props) => {
const types = [
{id:'default'},
{id:'custom'}
];
const [checked,setChecked] = useState(true);
const onClickType = (id) => {
(id === "custom") ? setChecked(false) : setChecked(true)
}
return (
<Create title='Create an Job' {...props}>
<SimpleForm>
<TextInput source='source' />
<TextInput source='destination' />
<RadioButtonGroupInput label="Type"
source="custom"
choices={types}
optionText="id"
onChange={onClickType} />
<RadioButtonGroupInput source="category" choices={[
{ id: 'default', name: 'default' },
{ id: 'custom', name: 'custom' },
]} />
{!checked && (
<SimpleShowLayout source="video">
<TextInput label='voice' name="codec" required />
</SimpleShowLayout>
)}
{ !checked && (
<ArrayInput source="Profiles">
<SimpleFormIterator disableReordering>
<TextInput label='Name' source="Name" required />
<TextInput label='Profile' source="profile" required />
</SimpleFormIterator>
</ArrayInput>
)}
{!checked && (
<SimpleShowLayout source="audios">
<TextInput label='audio1' required />
<TextInput label='audio2' required />
</SimpleShowLayout></source>
)}
</SimpleForm>
</Create>
)
}
export default JobCreate
I want to create complex UI using the react-admin framework, I have created the UI but when hit the save button, not getting actual or expected JSON in the output while sending to the api.
I tried so many ways, but no luck, Hence posting this question.
Here is the documentation link : https://marmelab.com/react-admin/Readme.html

How do you solve: undefined is not an object (evaluating 'this.panResponder.panHandlers')?

Hi my friend how to solve this problem,I have the following sourcode :
import React, { Component } from 'react';
import { Container, Header, Content, SwipeRow, View, Text, Icon, Button } from 'native-base';
class SwipeRowExample extends Component {
render() {
return (
<Container>
<Header />
<Content scrollEnabled={false}>
<SwipeRow
leftOpenValue={75}
rightOpenValue={-75}
left={
<Button success onPress={() => alert('Add')}>
<Icon active name="add" />
</Button>
}
body={
<View>
<Text>SwipeRow Body Text</Text>
</View>
}
right={
<Button danger onPress={() => alert('Trash')}>
<Icon active name="trash" />
</Button>
}
/>
</Content>
</Container>
);
}
}
export default SwipeRowExample;
Message obtained: undefined is not an object (evaluating 'this.panResponder.panHandlers')
But the results displayed :
SwipeRow was removed from the latest version and they recommend react-native-swipe-list-view
to use SwipeRow change native base version to 2.12.0
SwipeRow (removed)

Anyone knows why the label of picker in react native doesn't work?

I was trying to solve the problem by removing the item from but it seems didn't work. i wonder, am i forgot to pass something into the command?
hopefully, the screen and my code will make my explanation more briefly
Here is my code
EmployeeCreate.js
import React,{Component} from 'react';
import { Picker, Text } from 'react-native';
import { connect } from 'react-redux';
import { employeeUpdate } from '../actions';
import {Card,CardSection,Input,Button} from './common';
class EmployeeCreate extends Component {
render () {
return (
<Card>
<CardSection>
<Input
label="Name"
placeholder="jane"
/>
</CardSection>
<CardSection>
<Input
label="Phone"
placeholder="08122030930"
/>
</CardSection>
<CardSection style={{flexDirection:'column'}}>
<Text style={styles.pickerTextStyle}>Select your shift</Text>
<Picker
selectedValue={this.props.shift}
onValueChange={day => this.props.employeeUpdate ({prop:'shift' , value: day})}
>
<Picker.item label="Monday" value="Monday" />
<Picker.item label="Tuesday" value="Tuesday" />
<Picker.item label="Wednesday" value="Wednesday" />
<Picker.item label="Thursday" value="Thursday" />
<Picker.item label="Friday" value="Friday" />
<Picker.item label="Saturday" value="Saturday" />
<Picker.item label="Sunday" value="Sunday" />
</Picker>
</CardSection>
<CardSection>
<Button>
create
</Button>
</CardSection>
</Card>
);
}
}
const styles = {
pickerTextStyle: {
fontSize: 18,
paddingLeft: 20
}
};
const mapStateToProps =(state) => {
const { name,phone,shift } = state.employeeForm ;
return {name,phone,shift};
};
export default connect (mapStateToProps,{employeeUpdate}) (EmployeeCreate)
;
here attached also the picture of it
enter image description here
If the function that you mean to call is employeeUpdate that you have imported from ./actions, then you should remove this.props.
Else, the function may need to be defined in the parent class of EmployeeCreate.

failed to align checkbox in react-native elements

I am new to react-native,I am trying to create a simple page using all input components from react-native elements 1.00 beta4.My problem is I failed to align checkbox near my text component even if the parent view flexdirection is in 'row'.
register.js
import React,{ Component } from 'react';
import { Field,reduxForm } from 'redux-form';
import { View,Button } from 'react-native';
import {Icon,CheckBox,Text,Input} from 'react-native-elements';
const renderField=({label,keyboardType,name,icon,iconType}) => {
return(
<View style={{flexDirection:'row'}}>
<Input placeholder={label} inputContainerStyle={{borderWidth:2,borderColor:'lightgrey',borderRadius:20}} inputStyle={{color:'grey'}} leftIcon={<Icon size={25} type={iconType} name={icon} color="grey" />} errorStyle={{fontSize:15}} errorMessage="error" />
</View>
)
}
const checkBoxField=({label,keyboardType,name}) => {
return(
<View style={{flexDirection:'row'}}>
<Text>{label}</Text>
<CheckBox title='Male' checkedIcon='dot-circle-o' uncheckedIcon='circle-o' checked={true} containerStyle={{backgroundColor:'transparent'}} />
</View>
)
}
const RegisterForm=props => {
const {handleSubmit}=props;
return(
<View style={{flex:1,flexDirection:'column',margin:20,justifyContent:'flex-start',alignItems:'center'}}>
<Field label="Username" component={renderField} name="username" icon="user" iconType="font-awesome" />
<Field label="Email" component={renderField} name="username" icon="email" iconType="zocial" />
<Field label="Gender" component={checkBoxField} name="gender" />
<Button title='SUBMIT' onPress={handleSubmit} />
</View>
)
}
const Register=reduxForm({
form:'register',
})(RegisterForm);
export default Register;
output
what is the problem here?How can I align my checkbox (using flexbox algorithm)
you can use flex property like justifyContent and alginItem or you can also use Text property like alignText, and alignSelf.
const checkBoxField=({label,keyboardType,name}) => {
return(
<View style={{flexDirection:'row',alignItems:'center',justifyContent:'center'}}>
<Text style={{alignSelf:'center',textAlign:'center'}}>{label}</Text>
<CheckBox title='Male' checkedIcon='dot-circle-o' uncheckedIcon='circle-o' checked={true} containerStyle={{backgroundColor:'transparent'}} />
</View>
)
}

redux form returns nothing when calling submit function in react native

I am trying to create a simple redux form with react native,but when I call submit function it returns an empty array?
import React,{ Component } from 'react';
import { Field,reduxForm } from 'redux-form';
import { Text,Input } from 'react-native-elements';
import { View,Button } from 'react-native';
import {Icon,CheckBox} from 'react-native-elements';
const renderField=({label,keyboardType,name,icon,iconType}) => {
return(
<View style={{flexDirection:'row'}}>
<Input keyboardType={keyboardType} placeholder={label} inputContainerStyle={{borderWidth:2,borderColor:'lightgrey',borderRadius:20}} inputStyle={{color:'grey'}} leftIcon={<Icon size={25} type={iconType} name={icon} color="grey" />} errorStyle={{fontSize:15}} errorMessage="error" />
</View>
)
}
const checkBoxField=({label,keyboardType,name}) => {
return(
<View style={{flexDirection:'row'}}>
<Text>{label}</Text>
<CheckBox title='Male' checkedIcon='dot-circle-o' uncheckedIcon='circle-o' checked={true} containerStyle={{backgroundColor:'transparent',marginBottom:10}} />
</View>
)
}
const submit=values=>{
console.log(values)
}
const RegisterForm=props => {
const {handleSubmit}=props;
return(
<View style={{flex:1,flexDirection:'column',margin:20,justifyContent:'flex-start',alignItems:'center'}}>
<Field label="Username" component={renderField} name="username" icon="user" iconType="font-awesome" />
<Field label="Email" component={renderField} name="email" icon="email" iconType="zocial" />
<Field label="Gender" component={checkBoxField} name="gender" />
<Button title='SUBMIT' onPress={handleSubmit(submit)} />
</View>
)
}
const Register=reduxForm({
form:'register',
})(RegisterForm);
export default Register;
In the above code when clicking on the submit button it will call submit function with parameters,but nothing will printed in console.what the issue is here?
When you press the submit button you are calling props.handleSubmit() with your submit function, but the onPress() handler from the Button component does not accept any arguments.
So your submit() function never actually gets called.