Below is the button group component which I used inside the form.How to implement the onchange functions to this button group.I have no Idea how to set the onchange method
import React, {Component} from "react";
import {Popover, OverlayTrigger} from 'react-bootstrap';
import "./ButtonGroup.scss";
const popoverBottom = () =>{
return (
<Popover className="tooltip-popover" title="Here is the where you
give a tooltip">
</Popover>
);
}
export const ButtonGroup = ({
tooltip,
label,
options,
selected,
lableStyle = {},
Title = "Tooltip on top",
}) => {
return (
<div className="nuclei-group">
<p className="nuclei-buttongroup-input"> {label} </p>
<div data-toggle="buttons">
{options.map((option, i) => {
const className = selected == option.value ? "active" : "";
return (
<label
key={i}
style={lableStyle}
className={`btn btn-default nuclei-selection-option ${className}`}
>
<input
type="radio"
name={"name"}
id={option.value}
autoComplete="off"
/>
{option.label}
</label>
);
})}
{tooltip ? (
<span>
<OverlayTrigger trigger="click" rootClose placement="bottom" overlay={popoverBottom()}>
<button type="button" className="btn nuclei-tooltip">?</button>
</OverlayTrigger>
</span>
) : null}
</div>
</div>
);
};
export default ButtonGroup;
then I tried to add on change as below and after submitting the form it doesn't work can somebody help me to resolve it.Normally inside a input tag it works but here? and let me know is this the best way to get values from a form as in the code below
import React, {Component} from "react";
import "./classic-quote.scss";
import {Button, ButtonGroup, InputText} from "../../../components";
import StepBreadcrumb from "../../../components/StepBreadcrumb";
import HeaderTitle from "../../../components/HeaderTitle";
import axios from 'axios';
export default class ClassicQuote extends Component {
constructor(props){
super(props);
this.state = {
insurance_type:'',
vehicle_registration:'',
lease_loan_hire:'',
estimated_market_value:'',
usage:'',
make:'',
model:'',
year:'',
claim_bonus_year:''
}
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange1 = this.handleChange1.bind(this);
this.handleChange2 = this.handleChange2.bind(this);
this.handleChange3 = this.handleChange3.bind(this);
this.handleChange4 = this.handleChange4.bind(this);
}
handleChange1(e){
this.setState({
make: e.target.value
})
}
handleChange2(e){
this.setState({
model: e.target.value
})
}
handleChange3(e){
this.setState({
year: e.target.value
})
}
handleChange4(e){
this.setState({
insurance_type: e.target.id
})
}
handleSubmit(e){
e.preventDefault();
const quotation = {
make: this.state.make,
model: this.state.model,
year: this.state.year,
insurance_type: this.state.insurance_type
}
console.log('gggggggg'+quotation.make+quotation.model+quotation.year+quotation.insurance_type);
let uri = '/items'
axios.post(uri,quotation).then(response => {
console.log('ela');
}).then(error => {
console.log(error);
});
}
render() {
return <div>
{/* <StepBreadcrumb id="bred" /> */}
<div className="container insureme-form zero-padding">
<form onSubmit={this.handleSubmit}>
<div className="row">
<HeaderTitle mainFirstWord="Insurance" restOfTitle="Detail" headerStyle={{fontWeight: "bold"}} headerIcon={true} />
<div className="nuclei-insurance-detail-step-one">
<div className="col-md-12 col-sm-12 col-xs-12">
<ButtonGroup onChange={this.handleChange4} label="" selected="full" options={[{label: "Full Insurance", value: "full"}, {label: "3rd Party Insurance", value: "3rd"}]} tooltip />
<pre>{JSON.stringify(this.state, '', 2)}</pre>
</div>
<div className="col-md-12 col-sm-12 col-xs-12">
<ButtonGroup label="Do you have a vehicle registration No?" selected="Yes" options={[{label: "Yes", value: "Yes"}, {label: "No", value: "No"}]} tooltip />
</div>
<div className="col-md-12 col-sm-12 col-xs-12">
<ButtonGroup label="Do you have any lease,Loan or hire on vehicle?" selected="Yes" options={[{label: "Yes", value: "Yes"}, {label: "No", value: "No"}]} tooltip />
</div>
<div className="col-md-4 col-sm-4 col-xs-8">
<InputText label={"Estimated Market Value?"} placeholder="Rs." />
</div>
<div className="col-md-12 col-sm-12 col-xs-12">
<ButtonGroup label="Usage?" selected="Private" options={[{label: "Private", value: "Private"}, {label: "Hire", value: "Hire"}, {label: "Rent", value: "Rent"}]} tooltip />
</div>
<div className="col-md-12 col-sm-12 col-xs-12 form-group input-text ">
<label>Make, Model and Year of Manufacture? </label>
<div className="col-md-4 col-sm-4 col-xs-4 zero-padding-left">
<input type="text" className="form-control" id={"make-manufacture"} placeholder={"Make"} onChange={this.handleChange1} />
</div>
<div className="col-md-3 col-sm-3 col-xs-4 zero-padding-left">
<input type="text" className="form-control" id={"model-manufacture"} placeholder={"Model"} onChange={this.handleChange2}/>
</div>
<div className="col-md-2 col-sm-2 col-xs-3 zero-padding-left">
<input type="text" className="form-control" id={"year-manufacture"} placeholder={"Year"} onChange={this.handleChange3}/>
</div>
</div>
<div className="col-md-12 col-sm-12 col-xs-12 form-group input-text">
<label>No Claims Bonus?</label>
<div className="col-md-4 col-sm-4 col-xs-8 zero-padding-left">
<InputText tooltip placeholder="No. of Years" />
</div>
</div>
<div className="col-md-12 col-sm-12 col-xs-12">
<Button type="submit" color="red" className="nuclei-bottom-red-button">
Get a Quick Quote
</Button>
<Button type="clear" color="gray" className="nuclei-bottom-gray-button">
Clear
</Button>
</div>
</div>
</div>
</form>
</div>
</div>;
}
}
I tried several ways can get only the make model and year values as printed in the console log
if you want to pass an handler like this:
onChange={this.handleChange4}
you have to add it to the props you receive in Component:
export const ButtonGroup = ({
onChange,
tooltip,
label,
options,
selected,
lableStyle = {},
Title = "Tooltip on top",
}) => {
...
and then in the input elements call onChange:
<input
onChange={onChange}
type="radio"
name={"name"}
id={option.value}
autoComplete="off"
/>
If you want to see the complete solution, I build it in sandbox: Full example here
I saw that you update the form, but you didn't add "onChange" in the ButtonGroup Component file like in the comment:
export const ButtonGroup = ({
onChange, <---this
tooltip,
label,
options,
selected,
lableStyle = {},
Title = "Tooltip on top",
}) => {
return (
<div className="nuclei-group">
<p className="nuclei-buttongroup-input"> {label} </p>
<div data-toggle="buttons">
{options.map((option, i) => {
const className = selected == option.value ? "active" : "";
return (
<label
key={i}
style={lableStyle}
className={`btn btn-default nuclei-selection-option ${className}`}
>
<input
onChange={onChange} <---this
type="radio"
name={"name"}
id={option.value}
autoComplete="off"
/>
{option.label}
</label>
);
})}
Related
I have some trouble using the React Grid of Syncfusion. I want to edit some rows using my own Dialog Template. Calling it with the edit mode = 'Dialog' gives me the default Dialog, which automatically display every data set up in the columns.
Abviously one data row has more than the informations displayed. So I don't know how to set up the GridComponent to use my own Dialog in which I would show every column needed to be edited or added once I save the Grid.
I would be pleased if someone can help me. I guess, my thinking isn't right, bebause nothing seems to changed. I red the documention on the syncfusion officially page and somehow I can't figure it out.
https://help.syncfusion.com/reactjs/grid/editing#dialog-template-form
Here is React Component:
import React, { useEffect, useState } from 'react';
import axios from 'axios';
import { GridComponent, ColumnsDirective, ColumnDirective, Group, Resize, Sort, Search,
ContextMenu, Filter, Page, ExcelExport, PdfExport, Edit, Inject, Toolbar } from '#syncfusion/ej2-react-grids';
import { contextMenuItems, txGridHeader } from '../data/dummy';
import { Header } from '../components';
import { NumericTextBoxComponent } from '#syncfusion/ej2-react-inputs';
import { DatePickerComponent } from '#syncfusion/ej2-react-calendars';
import { DropDownListComponent } from '#syncfusion/ej2-react-dropdowns';
const url = 'https://xxxxxxxxxxxxxxxx/';
const TransactionForm = data => {
return (<div>
<div className="form-row">
<div className="form-group col-md-6">
<div className="e-float-input e-control-wrapper">
<input ref={input=> data.id = input} id="OrderID" name="OrderID" type="text" disabled={!data.isAdd} value={data.OrderID} onChange={this.onChange.bind(this)} />
<span className="e-float-line"></span>
<label className="e-float-text e-label-top"> Order ID</label>
</div>
</div>
<div className="form-group col-md-6">
<div className="e-float-input e-control-wrapper" >
<input ref={input=> this.customerName = input} value={data.CustomerName} id="CustomerName" name="CustomerName" type="text" onChange={this.onChange.bind(this)} />
<span className="e-float-line"></span>
<label className="e-float-text e-label-top">Customer Name</label>
</div>
</div>
</div>
<div className="form-row">
<div className="form-group col-md-6">
<NumericTextBoxComponent id="Freight" format='C2' value={data.Freight} placeholder="Freight" floatLabelType='Always'></NumericTextBoxComponent>
</div>
<div className="form-group col-md-6">
<DatePickerComponent id="OrderDate" value={data.OrderDate} placeholder="Order Date" floatLabelType='Always'></DatePickerComponent>
</div>
</div>
<div className="form-row">
<div className="form-group col-md-6">
<DropDownListComponent id="ShipCountry" value={data.ShipCountry} dataSource={this.shipCountryDistinctData}
fields={{text: 'ShipCountry', value: 'ShipCountry' }} placeholder="Ship Country"
popupHeight='300px' floatLabelType='Always'></DropDownListComponent>
</div>
<div className="form-group col-md-6">
<DropDownListComponent id="ShipCity" value={data.ShipCity} dataSource={this.shipCityDistinctData}
fields={{text: 'ShipCity', value: 'ShipCity' }} placeholder="Ship City"
popupHeight='300px' floatLabelType='Always'></DropDownListComponent>
</div>
</div>
<div className="form-row">
<div className="form-group col-md-12">
<div className="e-float-input e-control-wrapper">
<textarea id="ShipAddress" name="ShipAddress" value={data.ShipAddress} onChange={this.onChange.bind(this)} ></textarea>
<span className="e-float-line"></span>
<label className="e-float-text e-label-top">Ship Address</label>
</div>
</div>
</div>
</div>);
}
const Transactions = () => {
const [transaction, setTransaction] = useState(null);
useEffect(() => {
axios.get(url + 'transaction/')
.then(response => {
setTransaction(response.data)
})
}, []);
return (
<div className='m-2 md:m-10 p-2 md:p-10 bg-white rounded-3xl dark:bg-secondary-dark-bg dark'>
<Header category="Page" title="Transactions" />
<GridComponent id='gridcomp' dataSource={transaction} pageSettings={{ pageSize: 15}}
allowGrouping allowPaging allowSorting
allowExcelExport toolbar={['Add', 'Edit', 'Delete', 'Update', 'Cancel', 'Search']} width='auto'
editSettings={{allowAdding: true, allowEditing: true, allowDeleting: true, mode: 'Dialog'}}
editSettingsTemplate= {{TransactionForm}}>
<ColumnsDirective>
{txGridHeader.map((item, index) => (
<ColumnDirective key={index} {...item} />
))}
</ColumnsDirective>
<Inject services={[ Resize, Search, Sort, Group, ContextMenu,
Filter, Page, Edit, ExcelExport, PdfExport, Toolbar ]} />
</GridComponent>
</div>
)
}
export default Transactions
Try removing the editSettingsTemplate, and add the template inside inside the editSettings.
editSettings={{
allowAdding: true,
allowEditing: true,
allowDeleting: true,
mode: "Dialog",
template: TransactionForm,
}}
I have react form state. After submitting the form I want to send the input values to other component and then showing to browser. I successfully submit the form but when I sent the porps to other component. It does not show anything.
Here is my hero component
import React from "react";
import "./App.css";
import Show from "./Show";
function App() {
const [state, setState] = React.useState({
input: " ",
text: " "
});
const changeHandler = e => {
setState({ ...state, [e.target.id]: e.target.value });
};
const handleSubmit = e => {
e.preventDefault();
console.log(state);
return <Show show={state} />; //this is the component where I am sending props
};
return (
<React.Fragment>
<div className="row">
<form className="col s12" onSubmit={handleSubmit}>
<div className="row">
<div className="input-field col s3">
<input
id="input"
type="text"
data-length="4"
onChange={changeHandler}
/>
<label htmlFor="input_text">Input text</label>
</div>
</div>
<div className="row">
<div className="input-field col s8">
<textarea
id="text"
className="materialize-textarea"
data-length="120"
onChange={changeHandler}
></textarea>
<label htmlFor="textarea2">Right your text</label>
</div>
</div>
<button
className="btn waves-effect blue lighten-1"
type="submit"
name="action"
>
Submit
</button>
</form>
<Show /> //After submit the form I want to show to the browser
</div>
</React.Fragment>
);
}
export default App;
Here is my child component.
import React from "react";
export default function Show({ show }) {
return (
<div>
{show ? (
<ul>
<li>{show.input}</li>
<li>{show.text}</li>
</ul>
) : null}
</div>
);
}
ps: Ignore this message.In order to upload this post I need to. write more 😀.
Calling Method was wrong
handleSubmit is the event activity call .its not component
Inside the handleSubmit component return is not right one
So better pass state value on Show component inside the parent fragment
const handleSubmit = e => {
e.preventDefault();
console.log(state);
};
return (
<React.Fragment>
<div className="row">
<form className="col s12" onSubmit={handleSubmit}>
<div className="row">
<div className="input-field col s3">
<input
id="input"
type="text"
data-length="4"
onChange={changeHandler}
/>
<label htmlFor="input_text">Input text</label>
</div>
</div>
<div className="row">
<div className="input-field col s8">
<textarea
id="text"
className="materialize-textarea"
data-length="120"
onChange={changeHandler}
></textarea>
<label htmlFor="textarea2">Right your text</label>
</div>
</div>
<button
className="btn waves-effect blue lighten-1"
type="submit"
name="action"
>
Submit
</button>
</form>
<Show show={state} /> //pass state directly
</div>
</React.Fragment>
);
Opening a modal in edit with all the value but radio button is not checked while condition is true. What am I doing wrong here and should this.state.value be checked?
import React, { Component } from 'react';
import { MDBContainer, MDBBtn, MDBModal, MDBModalBody, MDBModalFooter, MDBInputGroup } from 'mdbreact';
import InputForm from './productsinputfield';
import Collection from './collectionpopup';
import Product from './productpopup';
import axios from 'axios';
This is the class:
class ModalPage extends Component {
addToArr = [{ id: 1, shippingValue: 20, taxValue: 20, shipingStatus: 0, taxStaus: 1 }]
state = {
modal13: false,
tag_name: 'Rajat Srivastava',
status: false,
valueStatus: false,
quantityStatus: false,
}
// This is the function which is calling in every render what
// I want whenever this will be called on edit then radio buttons
// should be checked:
componentDidMount() {
// The Props Data Is Coming From Another Component
if (this.props.sendRowData) {
// This condition is true but still unable to checked radio button:
if(this.props.sendRowData.cart_status == 1){
this.setState({ valueStatus : true });
}else if(this.props.sendRowData.cart_status == 2){
this.setState({quantityStatus : true});
}
}
}
showPopUP(nr) {
let modalNumber = 'modal' + nr
this.setState({
...this.state,
[modalNumber]: !this.state[modalNumber],
status: !this.state.status,
});
this.setState({ name: 'Rajat Srivastava' });
}
This is my JSX code
render() {
return (
<div className="row">
<div className="col-lg-2"></div>
<div className="col-lg-8">
<MDBContainer>
<MDBBtn color="primary" className="floatDiv" onClick={() => this.showPopUP(13)}>
Create Discount Tag
</MDBBtn>
{
this.state.status && <MDBModal isOpen={this.state.modal13} toggle={() => this.showPopUP(13)} size="lg">
<MDBModalBody>
<MDBContainer size="lg">
<form action="#" onSubmit={this.saveTagSettings}>
<h6>Set Products <span style={{ color: "red" }}> * </span></h6><br />
<div className="card card-header">
<div className="form-check card-header">
<div className="marginLeft">
<input className="form-check-input" type="radio" name="product" id="product" checked={this.state.valueStatus} value="1" onChange={(e) => this.handleProductRadio(e, 'minCartVal')} />
<label className="form-check-label" htmlFor="product">
Minimum Cart Value
</label>
</div>
</div>
<div className="form-check card-header">
<div className="marginLeft">
<input className="form-check-input" type="radio" name="product" id="product" checked={this.state.quantityStatus} value="2" onChange={(e) => this.handleProductRadio(e, 'minCartQua')} />
<label className="form-check-label" htmlFor="product">
Minimum Cart Quantity
</label>
</div>
</div>
</div>
<MDBBtn color="primary" type="submit">Save Tag</MDBBtn>
</form>
</MDBContainer>
</MDBModalBody>
<MDBModalFooter>
<MDBBtn color="secondary" onClick={() => this.showPopUP(13)}>
Close
</MDBBtn>
</MDBModalFooter>
</MDBModal>
}
</MDBContainer>
</div>
<div className="col-lg-2"></div>
</div>
);
}
}
export default ModalPage;
Is there a way to pass some initialvalue and update them when the tab is clicked and validate only a particular set of fields
import React, { Component } from 'react'
import { connect } from 'react-redux'
import {Field,reduxForm} from 'redux-form'
import { selectreport, decrementStep } from '../../actions.js'
class Step1 extends Component {
constructor (props) {
super(props)
this.handleChangeTab = this.handleChangeTab.bind(this)
this.stepBack = this.stepBack.bind(this)
}
stepBack (e) {
e.preventDefault()
console.log('reduce step by 1')
this.props.dispatch(decrementStep(this.props.step))
}
handleChangeTab (e) {
const { title: key } = e.target
console.log('click values are ', key)
this.props.dispatch(selectreport(key))
}
renderField(field){
const className = `row form-group ${field.meta.touched && field.meta.error ? 'has-error' : ''}`;
return(
<div className=" col-xs-12 col-md-offset-3 col-md-9">
<div className={className}>
<label className="col-xs-12 col-lg-12">{field.label}</label>
<input
type="text"
placeholder={field.placeholder}
className="form-control"
{...field.input} />
<div className="text-danger">
{field.meta.touched ? field.meta.error : ''}
</div>
</div>
</div>
);
}
onSubmit(values){
const { step, report } = this.props
}
render () {
const { step, report, parsedAddress,handleSubmit } = this.props
const { Line1, Line2} = parsedAddress
let st = JSON.stringify(step)
return (
<form className="" onSubmit={handleSubmit(this.onSubmit.bind(this))}>
<div className="">
<div className="row">
<div className="col-xs-10 col-md-6 col-xs-offset-1 col-md-offset-3">Enter details.</div>
</div>
<div className="row">
<div className="nav nav-pills col-xs-10 col-md-6 col-xs-offset-1 col-md-offset-3 PADD0">
<div className={report == 'address' ? ('col-xs-6 active') : 'col-xs-6'}>
<a data-toggle="tab" href="#address" title="address" onClick={this.handleChangeTab}>Address</a></div>
<div className={report == 'phone' ? 'col-xs-6 active' : 'col-xs-6'}>
<a data-toggle="tab" href="#phone" title="phone" onClick={this.handleChangeTab}>Phone</a></div>
</div>
</div>
<div className="row">
<div className="tab-content PADD20PX text-centered col-sm-offset-1 col-sm-10 col-md-offset-2 col-md-6 ">
<div id="address" className={report == 'address' ? 'tab-pane fade in PADD20PX active' : 'tab-pane fade in PADD20PX'}>
<Field
label="Address"
name="Line1"
placeholder="123 Sample Street"
component={this.renderField}
/>
<Field
label="address2"
name="Line2"
placeholder="APT"
component={this.renderField}
/>
</div>
<div id="phone" className={report == 'phone' ? 'tab-pane fade in PADD20PX active' : 'tab-pane fade in PADD20PX'}>
<Field
label="PhoneNumber"
name="phone"
placeholder="123.456.7890"
component={this.renderField}
/>
</div>
</div>
</div>
</div>
<div className="row PADDBOX">
<div className="col-xs-12">
<div className="pull-left">
<div className="pull-left">
<button type="button btn-rounded" onClick={this.stepBack} className="btn btn-default">Back</button>
</div>
</div>
<div className="pull-right"><button type="submit">Search</button></div>
</div>
</div>
</form>
</div>
)
}
}
function validate(values,props){
console.log("inside validate",props);
const errors = {};
if(!values.Line1){
errors.Line1 = "Enter address";
}
if(!values.Line2){
errors.Line2 = "Enter address";
}
if(!values.phone){
errors.phone = "Enter phone number";
}
return errors;
}
function mapStateToProps (state) {
return {
step: state.step,
parsedAddress: state.parsedAddress,
report: state.report
}
}
export default reduxForm({destroyOnUnmount: false,validate,form:'PostsnewForm'})(
connect(mapStateToProps)(Step1)
);
Have two tabs one for address and phone.
Trying to submit the form while on address tab, cant submit even if I pass all the validations since the validation on phone tab fails
Is there a way to pass a global state to the validate function and validate particular fields based on an attribute in global state.
Try this:
function validate(values) {
// console.log(values) -> {title: 'asdf', categories: 'asdf', content: 'asdf'}
const errors = {};
// validate the inputs from 'values'
if (!values.title || values.title.length < 3) {
errors.title = "Enter a title that is at least 3 characters!";;
}
// if errors is empty, the form is fine to submit
// If errors have any properties, redux form assumes form is invalid
return errors;
}
if (!values.categories) {
errors.categories = 'Enter some categories';
}
if (!values.content) {
errors.content = 'Enter some content, please';
}
export default reduxForm({
validate,
form: 'PostsNewForm'
})(PostsNew);
an if statement for the fields you do want to validate.
import React, { Component } from 'react';
class BigText extends Component {
constructor(props) {
super(props);
this.state = {
title: '',
text: '',
summary: ''
};
this.handleInputChange = this.handleInputChange.bind(this);
}
handleInputChange(event) {
this.setState({
[event.target.name]: event.target.value
});
}
render() {
return (
<div>
<div>
<div className="row animated fadeIn">
<div className="px-1" style={{ width:100 + '%' }}><br />
<div className="mb-1">
<input type="text"
className="form-control"
placeholder="Title"
name="title"
value={this.state.title}
onChange={this.handleInputChange}
/>
</div>
<div className="mb-1">
<textarea
className="form-control"
placeholder="Text"
name="text"
value={this.state.text}
onChange={this.handleInputChange}
/>
</div>
<div className="mb-1">
<textarea
className="form-control"
placeholder="Summary"
name="summary"
value={this.state.summary}
onChange={this.handleInputChange}
/>
</div>
</div>
<div>
</div>
</div>
</div>
</div>
)
}
}
export default BigText;
import React, { Component } from 'react';
import BigText from './bigText.js';
import InboxStyle from './inboxStyle.js';
import ImageStyle from './imageStyle.js';
import BigTextMobile from './bigText.mobile.js';
import InboxStyleMobile from './inboxStyle.mobile.js';
import ImageStyleMobile from './imageStyle.mobile.js';
class BasicNotification extends Component {
constructor(props) {
super(props);
this.state = {value: ''};
this.handleClick = this.handleClick.bind(this);
}
static contextTypes = {
router: React.PropTypes.object
}
handleClick() {
this.context.router.push('/notifications');
}
handleChange(event) {
this.setState({value: event.target.value});
}
checkRadio =(e) =>{
if(e.target.checked) {
this.setState({layout: e.target.value});
}
}
render() {
return (
<div>
<div>
<h1 className="px-2">Create Notification</h1>
<hr />
<div className="row px-1 py-2 animated fadeIn">
<div className="px-1 mr-2" style={{ width:50 + '%' }}><br />
<div className="mb-1">
<input type="text"
className="form-control"
placeholder="Title"
name="title"
/>
</div>
<div className="mb-1">
<textarea
className="form-control"
placeholder="Text"
name="text"
/>
</div>
<div>
<select placeholder="Logo" className="form-control" onChange={this.handleChange}>
<option default>Select Logo</option>
<option>Default</option>
<option>Custom</option>
</select>
</div>
<div><br />
<div className="btn-group" data-toggle="buttons">
<label className="btn btn-css btn-outline-secondary">
<input type="radio" name="layout" value="image" onChange={this.checkRadio}/>ImageStyle
</label>
<label className="btn btn-css btn-outline-secondary">
<input type="radio" name="layout" value="big" onChange={this.checkRadio}/>BigText
</label>
<label className="btn btn-css btn-outline-secondary">
<input type="radio" name="layout" value="inbox" onChange={this.checkRadio}/>InboxStyle
</label>
</div>
{
(this.state.layout === "big")?
<BigText/>:
(this.state.layout === "image")?
<ImageStyle/>:
(this.state.layout === "inbox")?
<InboxStyle/>:
null
}
<br />
<div className="row px-1" >
<div>
<button className="nav-link btn btn-block btn-info" onClick={this.handleClick} >Save</button>
</div>
<div className="px-1">
<button className="nav-link btn btn-block btn-danger"> Cancel</button>
</div>
</div>
</div><br />
</div>
<div>
{
(this.state.layout === "big")?
<BigTextMobile text={this.state.text} summary={this.state.summary} title={this.state.title}/>:
(this.state.layout === "image")?
<ImageStyleMobile/>:
(this.state.layout === "inbox")?
<InboxStyleMobile/>:
null
}
</div>
</div>
</div>
</div>
)
}
}
export default BasicNotification;
This is the screen i made on which I had imported three files which will be shown on clicking radio buttons.
Also there is a relevant mobile screen as well shown aside
now for example i imported as you can see BigText , it is containing the form
Now i want to print its input values in BigTextMobile Component
To simplify the solution you can do something like this:
<BigText onChange={data => {this.setState({ data })}} />
In the BigText component then you can put some data via this callback like this:
handleInputChange(event) {
const data = {
[event.target.name]: event.target.value
};
this.setState(data );
this.props.onChange(data);
}
And transfer this data to your BigTextMobile component from state:
<BigTextMobile data={this.state.data} ... />