How do I change the 'items' from a 'RNCPickerSelect' when I've selected a value from another 'RNCPickerSelect'?
For example, when I select a value called 'brand' from a RNCPickerSelect, the other RNCPickerSelect displays the 'models' associated with that specific 'brandName'. Basically, I want the 'items' from the other RNCPickerSelect to be influenced by the first RNCPickerSelect.
Here's the code:
================================Brands===================================
<RNPickerSelect
pickerProps={{ style: {overflow: 'hidden' } }}
onValueChange={(value) => console.log(value)}
placeholder={brandplaceholder}
// style={styles.dropbox}
items={[
{ label: 'brand1', value: 'brand1' },
{ label: 'brand2', value: 'brand2' },
{ label: 'brand3', value: 'brand3' },
]}
onValueChange={(val) => setBrand(val)}
/>
==========================================================================
=================================Models===================================
<RNPickerSelect
pickerProps={{ style: {overflow: 'hidden' } }}
onValueChange={(value) => console.log(value)}
placeholder={brandplaceholder}
// style={styles.dropbox}
items={[
{ label: 'model1', value: 'model1' },
{ label: 'model2', value: 'model2' },
{ label: 'model3', value: 'model3' },
]}
onValueChange={(val) => setModel(val)}
/>
==========================================================================
===============================Model Ideas================================
items={[
{ label: 'model4', value: 'model4' },
{ label: 'model5', value: 'model5' },
{ label: 'model6', value: 'model6' },
]}
**and**
items={[
{ label: 'model7', value: 'model7' },
{ label: 'model8', value: 'model8' },
{ label: 'model9', value: 'model9' },
]}
==========================================================================
Thanks!
With the codes provided by #FreakyCoder, I've successfully fixed and improved the 'RNCPickerSelect'. I have adjusted the code to fit my project and have added some extra lines of codes as well. Thanks again #FreakyCoder!
The Sample Codes:
export default function MainPage() {
//===============Example Selections===============//
const firstPick = [
{ label: 'Football', value: 'football' },
{ label: 'Baseball', value: 'baseball' },
{ label: 'Hockey', value: 'hockey' },
];
const secondPick = [
{ label: 'Football2', value: 'football2' },
{ label: 'Baseball2', value: 'baseball2' },
{ label: 'Hockey2', value: 'hockey2' },
];
const thirdPick = [
{ label: 'Football3', value: 'football3' },
{ label: 'Baseball3', value: 'baseball3' },
{ label: 'Hockey3', value: 'hockey3' },
];
//================================================//
const [dynamicPickerArr, setDynamicPickerArr] = useState(HondaModel)
return(
<RNPickerSelect
onValueChange={(value) => { setModel(value)
// Magic here
// Your changed value logic should be here
if(value=='football')
return Football=setDynamicPickerArr(thirdPick)
else if(value=='baseball')
return Baseball=setDynamicPickerArr(secondPick)
else if(value=='hockey')
return Baseball=setDynamicPickerArr(firstPick)
}
}
items={[
{ label: 'Football', value: 'football' },
{ label: 'Baseball', value: 'baseball' },
{ label: 'Hockey', value: 'hockey' },
]}
/>
<RNPickerSelect
onValueChange={(value) => console.log(value)}
items={dynamicPickerArr}
/>
)
}
you can do that with a simple state logic. When the first picker selects, it will update the other picker's predefined items array.
import React from "react";
import RNPickerSelect from 'react-native-picker-select';
const firstPick = [
{ label: 'Football', value: 'football' },
{ label: 'Baseball', value: 'baseball' },
{ label: 'Hockey', value: 'hockey' },
]
const secondPick = [[
{ label: 'Football2', value: 'football2' },
{ label: 'Baseball2', value: 'baseball2' },
{ label: 'Hockey2', value: 'hockey2' },
]
export const Dropdown = () => {
const [dynamicPickerArr, setDynamicPickerArr] = useState(firstPick)
return (
<RNPickerSelect
onValueChange={(value) => {
// Magic here
// Your changed value logic should be here
setDynamicPickerArr(secondPick)}
}
items={[
{ label: 'Football', value: 'football' },
{ label: 'Baseball', value: 'baseball' },
{ label: 'Hockey', value: 'hockey' },
]}
/>
<RNPickerSelect
onValueChange={(value) => console.log(value)}
items={}
/>
);
};
Related
this is i want to
const nestedMenuitems = ref([
{
label: 'Shipments',
icon: 'pi pi-fw pi-envelope',
items: [
{
label: 'store1',
icon: 'pi pi-fw pi-compass'
},
{
label: 'store2',
icon: 'pi pi-fw pi-compass'
},
]
},
]);
const nestedMenuitems = ref([
{
label: 'Shipments',
icon: 'pi pi-fw pi-envelope',
items: [
{
label: store_lables,
icon: 'pi pi-fw pi-compass'
},
]
},
]);
onMounted(() => {
ApiService.getStores().then((data) => {
stores.value = data;
stores.value.forEach((store_lables) => (store_lables));
// console.log( stores.value.forEach((store_lables) => ({
// label: store_lables.shop,
// icon: 'pi pi-fw pi-compass'
// })));
});
});
Here I get Api to data ApiService.getStores() this working fine.pass title values to ?(label: store_lables)
i get a error.
how to pass datas to items: [ {label: store_lables,icon: 'pi pi-fw pi-compass' }, ]
I have a credit card component. when user select expire month or expire year from select, I want to get value in p tag. Controller code is here, if I use render with controller its working but not giving error.
<Controller
as={<Select options={years} />}
name="expiryYear"
onChange={(inputValue) => changeValue(inputValue.value)}
control={control}
defaultValue={null}
rules={{
required: true
}}
/>
How it giving error when its null and get value in the p tag?
and here is the sandbox link https://codesandbox.io/s/cool-http-rbzfp
I think you want to use watch/usewatch to retrieve the input value:
https://react-hook-form.com/api#watch
https://react-hook-form.com/api#useController
import React, { useState } from "react";
import { useForm, Controller } from "react-hook-form";
import Select from "react-select";
const CreditCardForm = ({
cardInfo: { number, expiryMonth, expiryYear },
onChange
}) => {
const months = [
{ value: "01", label: "01" },
{ value: "02", label: "02" },
{ value: "03", label: "03" },
{ value: "04", label: "04" },
{ value: "05", label: "05" },
{ value: "06", label: "06" },
{ value: "07", label: "07" },
{ value: "08", label: "08" },
{ value: "09", label: "09" },
{ value: "10", label: "10" },
{ value: "11", label: "11" },
{ value: "12", label: "12" }
];
const years = [
{ value: "2021", label: "2021" },
{ value: "2022", label: "2022" },
{ value: "2023", label: "2023" },
{ value: "2024", label: "2024" },
{ value: "2025", label: "2025" },
{ value: "2026", label: "2026" },
{ value: "2027", label: "2027" },
{ value: "2028", label: "2028" },
{ value: "2029", label: "2029" }
];
const { register, errors, watch, formState, control } = useForm({
mode: "all",
reValidateMode: "onBlur"
});
console.log(watch());
function changeValue(inputValue) {
onChange({
key: "expiryMonth",
value: inputValue.label
});
}
function changeValue2(inputValue) {
onChange({
key: "expiryYear",
value: inputValue.label
});
}
return (
<form>
<div className="form-group expires">
<div className="expires__select">
{errors.expiryMonth && (
<span className="input__error-message">required</span>
)}
<Controller
as={<Select options={months} />}
name="expiryMonth"
// onChange={(inputValue) => changeValue(inputValue.value)}
control={control}
defaultValue={null}
rules={{
required: true
}}
/>
</div>
<div className="expires__select">
{errors.expiryYear && (
<span className="input__error-message">required</span>
)}
<Controller
as={<Select options={years} />}
name="expiryYear"
// onChange={(inputValue) => changeValue2(inputValue.value)}
control={control}
defaultValue={null}
rules={{
required: true
}}
/>
</div>
</div>
</form>
);
};
export default CreditCardForm;
I have a screen that has three bottom tabs, in one of the tab screens I want to move to a completely new page using Navigation.push but it's not working. Please anyone who can help out with switching from tab based view to push screen(that has no tabs. stack I guess)
below is my navigator.js file that contains the initial logic for switching to tabs view on login
Navigation.registerComponentWithRedux('HomeScreen', ()=> Home, Provider, store)
Navigation.registerComponentWithRedux('FindPlace', ()=> FindPlace, Provider, store)
Navigation.registerComponentWithRedux('SharePlace', ()=> SharePlace, Provider, store)
Navigation.registerComponent('PlaceDetailScreen', ()=> PlaceDetailScreen);
export const startNavigation = () => {
Promise.all([
Icon.getImageSource('ios-search', 30),
Icon.getImageSource('md-share', 30, 'blue'),
Icon.getImageSource('ios-home', 30, 'darkblue'),
]).then(icons => {
Navigation.setRoot({
root: {
bottomTabs: {
children: [
{
component: {
name: 'HomeScreen',
options: {
bottomTab: {
text: 'Home',
fontSize: 10,
icon: icons[2]
}
}
}
},
{
component: {
name: 'FindPlace',
options: {
bottomTab: {
text: 'Find a Place',
fontSize: 10,
icon: icons[0]
}
},
passProps: {
data: 'Data'
}
}
},
{
component: {
name: 'SharePlace',
options: {
bottomTab: {
text: 'Share Place',
fontSize: 10,
icon: icons[1]
}
}
}
}
]
}
}
})
})
}
below is my dummy login page that I use to call the tabs logic
import {startNavigation} from '../../../navigation';
const AuthScreen = props=> {
const navigateTabs = () => {
startNavigation()
}
return (
<View style={styles.authScreen}>
<TextInput placeholder='Username'/>
<Button title='Log me in' color='green' onPress={navigateTabs}/>
</View>
)
}
below is the code I am trying to use to push a new screen which is not working
const handleItemSelect = key => {
const selPlaces = places.places.find(item => item.key === key);
Navigation.push(props.componentId, {
component: {
name: 'PlaceDetailScreen',
options: {
topBar: {
visible: true,
title: {
text: selPlaces.name
}
}
},
passProps: {
selectedPlace: selPlaces
}
}
})
}
Solved it! the issue was with how I was setting the root in my main navigation.js file. I wasn't doing it properly.
here is the updated root as instructed here https://wix.github.io/react-native-navigation/#/docs/top-level-api?id=setrootlayout
bottomTabs: {
children: [
{
stack: {
children: [
{
component: {
name: 'HomeScreen',
options: {
bottomTab: {
text: 'Home',
fontSize: 10,
icon: icons[2]
},
topBar: {
visible: true,
leftButtons: [
{
id: 'sideMenu',
icon: icons[3]
}
],
noBorder: true
}
}
}
}
]
}
},
{
stack: {
children: [
{
component: {
name: 'FindPlace',
options: {
bottomTab: {
text: 'Find a Place',
fontSize: 10,
icon: icons[0]
},
topBar: {
leftButtons: [
{
id: 'sideMenu',
icon: icons[3]
}
],
noBorder: true
}
},
passProps: {
data: 'Data'
}
}
},
]
}
},
{
stack: {
children: [
{
component: {
name: 'SharePlace',
options: {
bottomTab: {
text: 'Share Place',
fontSize: 10,
icon: icons[1]
},
topBar: {
leftButtons: [
{
id: 'sideMenu',
icon: icons[3]
}
],
noBorder: true
}
},
passProps: {
data: 'data'
}
}
}
]
}
}
]
}
I'm trying to enable some operations on my grid such as grouping, filtering and sorting, individually they works as shown in the docs but there is no an example of those functionality working together.
By myself I was able to combine sorting and filtering but grouping does not work when i'm adding it as it shown in the docs. look at at my code
<template>
<div>
<Grid :style="{height: '100%'}"
ref="grid"
:data-items="getData"
:resizable="true"
:reorderable="true"
#columnreorder="columnReorder"
:filterable="true"
:filter="filter"
#filterchange="filterChange"
:sortable="true"
:sort= "sort"
#sortchange="sortChangeHandler"
:groupable="true"
:group= "group"
#dataStateChange="dataStateChange"
:columns="columns">
</Grid>
</div>
</template>
<script>
export default {
data() {
return {
items: [],
editID: null,
columns: [
{ field: 'AbsenceEmployeID', filterable:false, editable: false, title: '#'},
{ field: 'Employe', title: 'Employer', cell: DropDownEmployes},
{ field: 'Remarque', title: 'Remarque'},
{ field: 'Type', title: 'Type', cell: DropDownTypes},
{ field: 'CreatedDate', filter:'date', editable: false, editor: 'date', title: 'créé le', format: '{0:d}'},
{ title: 'Actions', filterable:false, cell: CommandCell}
],
filter: {
logic: "and",
filters: []
},
sort: [
{ field: 'CreatedDate', dir: 'desc' }
],
group: [],
gridData: []
}
}
mounted() {
this.loadItems()
},
computed: {
absencesList() {
return this.items.map((item) => Object.assign({ inEdit: item.AbsenceEmployeID === this.editID}, item));
},
getData() {
return orderBy(filterBy(this.absencesList, this.filter), this.sort);
},
...mapState({
absences: state => state.absences.absences
})
}
methods: {
loadItems () {
this.$store.dispatch('absences/getAbsences')
.then(resp => {
this.items = this.absences.map(item => item)
})
},
filterChange: function(ev) {
this.filter = ev.filter;
},
columnReorder: function(options) {
this.columns = options.columns;
},
sortChangeHandler: function(e) {
this.sort = e.sort;
},
// the following is for grouping but not yet used, read more
groupedData: function () {
this.gridData = process(this.getData, {group: this.group});
},
createAppState: function(dataState) {
this.group = dataState.group;
this.groupedData();
},
dataStateChange: function (event) {
this.createAppState(event.data);
},
}
}
</script>
The last three methods are not used yet, so filtering and sorting is working perfectly as of now. then in other to enable grouping I want to replace :data-items="getData" by :data-items="gridData" and run this.groupedData() method after the items are loaded but grouping doesn't work.
I think everything should be handle by the dataStateChange event and process() function but I also tried but without success
If you define the filterchange and sortchange events they are being triggered for filter and sort and you will have to updated data in their handlers. If you rather want to use datastatechage event for all the changes you have to remove the filterchange and sortchange events and the datastatechage event will be triggered instead of them. In this case you will have to update the data in its handler.
You can use the process method of #progress/kendo-data-query by passing the respective parameter each data change that is needed as in the example below:
const result = process(data, {
skip: 10,
take: 20,
group: [{
field: 'category.categoryName',
aggregates: [
{ aggregate: "sum", field: "unitPrice" },
{ aggregate: "sum", field: "unitsInStock" }
]
}],
sort: [{ field: 'productName', dir: 'desc' }],
filter: {
logic: "or",
filters: [
{ field: "discontinued", operator: "eq", value: true },
{ field: "unitPrice", operator: "lt", value: 22 }
]
}
});
Hers is a sample stackblitz example where such example is working correctly - https://stackblitz.com/edit/3ssy1k?file=index.html
You need to implement the groupchange method to handle Grouping
I prefer to use process from #progress/kendo-data-query
The following is a complete example of this
<template>
<Grid :style="{height: height}"
:data-items="gridData"
:skip="skip"
:take="take"
:total="total"
:pageable="pageable"
:page-size="pageSize"
:filterable="true"
:filter="filter"
:groupable="true"
:group="group"
:sortable="true"
:sort="sort"
:columns="columns"
#sortchange="sortChangeHandler"
#pagechange="pageChangeHandler"
#filterchange="filterChangeHandler"
#groupchange="groupChangeHandler"
/>
</template>
<script>
import '#progress/kendo-theme-default/dist/all.css';
import { Grid } from '#progress/kendo-vue-grid';
import { process } from '#progress/kendo-data-query';
const sampleProducts = [
{
'ProductID': 1,
'ProductName': 'Chai',
'UnitPrice': 18,
'Discontinued': false,
},
{
'ProductID': 2,
'ProductName': 'Chang',
'UnitPrice': 19,
'Discontinued': false,
},
{
'ProductID': 3,
'ProductName': 'Aniseed Syrup',
'UnitPrice': 10,
'Discontinued': false,
},
{
'ProductID': 4,
'ProductName': "Chef Anton's Cajun Seasoning",
'UnitPrice': 22,
'Discontinued': false,
},
];
export default {
components: {
Grid,
},
data () {
return {
gridData: sampleProducts,
filter: {
logic: 'and',
filters: [],
},
skip: 0,
take: 10,
pageSize: 5,
pageable: {
buttonCount: 5,
info: true,
type: 'numeric',
pageSizes: true,
previousNext: true,
},
sort: [],
group: [],
columns: [
{ field: 'ProductID', filterable: false, title: 'Product ID', width: '130px' },
{ field: 'ProductName', title: 'Product Name' },
{ field: 'UnitPrice', filter: 'numeric', title: 'Unit Price' },
{ field: 'Discontinued', filter: 'boolean', title: 'Discontinued' },
],
};
},
computed: {
total () {
return this.gridData ? this.gridData.length : 0;
},
},
mounted () {
this.getData();
},
methods: {
getData: function () {
this.gridData = process(sampleProducts,
{
skip: this.skip,
take: this.take,
group: this.group,
sort: this.sort,
filter: this.filter,
});
},
// ------------------Sorting------------------
sortChangeHandler: function (event) {
this.sort = event.sort;
this.getData();
},
// ------------------Paging------------------
pageChangeHandler: function (event) {
this.skip = event.page.skip;
this.take = event.page.take;
this.getData();
},
// ------------------Filter------------------
filterChangeHandler: function (event) {
this.filter = event.filter;
this.getData();
},
// ------------------Grouping------------------
groupChangeHandler: function (event) {
this.group = event.group;
this.getData();
},
},
};
</script>
Here's the sample code
I tried with update and other functions, none of them worked
launch: function() {
var categories = ['EMEA','APAC','AMERICAS'],
name = 'Browser brands',
data = [{
y: 55.11,
drilldown: {
name: 'EMEA versions',
categories: ['Cost', 'TechMe', 'disc', 'Matt'],
data: [
{
y: 40.11,
drilldown: {
name: 'Cost Drill',
categories: ['Page 1', 'Page 2', 'Page 3.0', 'Page 4.0'],
data: [0.20, 0.83, 1.58, 13.12, 5.43]
}
},
{
y: 40.11,
drilldown: {
name: 'Techme Drill',
categories: ['Page 1', 'Page 2', 'Page 3.0', 'Page 4.0'],
data: [1.58, 13.12, 5.43,0.20, 0.83]
}
},
{
y: 40.11,
drilldown: {
name: 'dISC Drill',
categories: ['Page 1', 'Page 2', 'Page 3.0', 'Page 4.0'],
data: [0.83, 1.58, 13.12,0.20, 5.43]
}
}
]
}
}, {
y: 21.63,
drilldown: {
name: 'Firefox versions',
categories: ['Firefox 2.0', 'Firefox 3.0', 'Firefox 3.5', 'Firefox 3.6', 'Firefox 4.0'],
data: [0.20, 0.83, 1.58, 13.12, 5.43]
}
}, {
y: 11.94,
drilldown: {
name: 'Chrome versions',
categories: ['Chrome 5.0', 'Chrome 6.0', 'Chrome 7.0', 'Chrome 8.0', 'Chrome 9.0',
'Chrome 10.0', 'Chrome 11.0', 'Chrome 12.0'],
data: [0.12, 0.19, 0.12, 0.36, 0.32, 9.91, 0.50, 0.22]
}
}, {
y: 7.15,
drilldown: {
name: 'Safari versions',
categories: ['Safari 5.0', 'Safari 4.0', 'Safari Win 5.0', 'Safari 4.1', 'Safari/Maxthon',
'Safari 3.1', 'Safari 4.1'],
data: [4.55, 1.42, 0.23, 0.21, 0.20, 0.19, 0.14]
}
}, {
y: 2.14,
drilldown: {
name: 'Opera versions',
categories: ['Opera 9.x', 'Opera 10.x', 'Opera 11.x'],
data: [ 0.12, 0.37, 1.65]
}
}];
Here's the setChart function which is called on click event of the chart
function setChart(chart,name, categories, data, color) {
var newchart=mychart;
var chartConfig={
chart: {
type: 'column'
},
title: {
text: 'Browser market share, April, 2011'
},
subtitle: {
text: 'Click the columns to view versions. Click again to view brands.'
},
xAxis: {
categories: categories
},
yAxis: {
title: {
text: 'Total percent market share'
}
},
plotOptions: {
column: {
cursor: 'pointer',
point: {
events: {
click: function() {
var drilldown = this.drilldown;
if (drilldown) { // drill down
setChart(this,drilldown.name, drilldown.categories, drilldown.data, drilldown.color);
} else { // restore
setChart(this,name, categories, data);
}
}
}
},
dataLabels: {
enabled: true,
style: {
fontWeight: 'bold'
},
formatter: function() {
return this.y +'%';
}
}
}
},
tooltip: {
formatter: function() {
var point = this.point,
s = this.x +':<b>'+ this.y +'% market share</b><br/>';
if (point.drilldown) {
s += 'Click to view '+ point.category +' versions';
} else {
s += 'Click to return to browser brands';
}
return s;
}
}
}
console.log("Before ",newchart.chartConfig);
newchart.setChartConfig(chartConfig);
console.log("After ",newchart.chartConfig);
var chartSeries={
name: name,
data: data,
color: 'white'
}
newchart.setChartData(chartSeries);
chart.remove('#myChart');
//chart.update(newchart);
//redrawChart(this,mychart);
//console.log(mychart);
// console.log(chart.setChartConfig());
//chart.x.setCategories(categories, false);
//chart.chartData.series[0].remove(false);
/*chart.chartData.addSeries({
name: name,
data: data,
color: color || 'white'
}, false);*/
//chart.redraw();
// mychart.update();
//mychart.updateLayout();
// mychart.show();
console.log("After " , mychart);
}
Main chart is here ...
var mychart=Ext.create('Rally.ui.chart.Chart', {
autoRender:true,
autoShow:true,
id:'myChart',
storeType : 'Rally.data.WsapiDataStore',
storeConfig : {
model: 'Defect'
//fetch : ["_ValidFrom", "_ValidTo", "10778908645", "ScheduleState", "Name"]
//filters : this.getColumnFilters()
},
calculatorType: 'My.Calculator',
calculatorConfig: {},
chartConfig: {
chart: {
type: 'column'
},
title: {
text: 'Browser market share, April, 2011'
},
subtitle: {
text: 'Click the columns to view versions. Click again to view brands.'
},
xAxis: {
categories: categories
},
yAxis: {
title: {
text: 'Total percent market share'
}
},
plotOptions: {
column: {
cursor: 'pointer',
point: {
events: {
click: function() {
var drilldown = this.drilldown;
if (drilldown) { // drill down
setChart(this,drilldown.name, drilldown.categories, drilldown.data, drilldown.color);
} else { // restore
setChart(this,name, categories, data);
}
}
}
},
dataLabels: {
enabled: true,
style: {
fontWeight: 'bold'
},
formatter: function() {
return this.y +'%';
}
}
}
},
tooltip: {
formatter: function() {
var point = this.point,
s = this.x +':<b>'+ this.y +'% market share</b><br/>';
if (point.drilldown) {
s += 'Click to view '+ point.category +' versions';
} else {
s += 'Click to return to browser brands';
}
return s;
}
}
},
chartData:{ // this works
series: [{
name: name,
data: data,
color: 'white'
}],
exporting: {
enabled: false
}
}
});
// add your code here
this.add(mychart); // add the component to rally interface
}
I want data to get changed on clicking
I have an example of chart update triggered by a button click in a github repo here.
Unlike a AppSDK2 grids that have a reconfigure method, AppSDK charts do not. In this example I delete a chart this.down("#myChart").removeAll() , modify metric definition of the calculator and then re-add the chart to the app.
You may also want to see this post.