After selecting an option from lightning-combobox the dropdown show "Select Progress" instead of the option I picked - salesforce-lightning

When I pick a value from the dropdown (Combobox) instead of keeping the value I picked the dropdown shows "Select Progress" instead.
How can I make the code show the value I picked...???
I am trying to show Start time on one of the Comboboxes and End time on the other, but every time that I pick an option the value disappears, and instead it shows "Select Progress". The same happens in the second Combobox.
The values get passed to the JS code correctly but are not staying in the dropdown.
HTML
<template>
<lightning-card>
<lightning-combobox
class="slds-var-m-around_medium"
name="progress"
label="Starts"
value={value1}
placeholder="Select Progress"
options={options1}
onchange={handleChange1} >
</lightning-combobox>
<lightning-combobox
class="slds-var-m-around_medium"
name="progress"
label="Ends"
value={value2}
placeholder="Select Progress"
options={options2}
onchange={handleChange2}>
</lightning-combobox>
<div class="slds-var-m-around_medium lgc-bg">
<lightning-input type="text" label="Duration" value={duration}></lightning-input>
</div>
</lightning-card>
</template>
JS
import { LightningElement, track } from 'lwc';
export default class Combobox extends LightningElement {
#track value1 = 0;
#track value2 = 0;
#track duration = 0;
#track options1 = [
{ label: '12:00 AM', value: 0 },
{ label: '12:15 AM', value: 0.25 },
{ label: '12:30 AM', value: 0.50 },
{ label: '12:45 AM', value: 0.75 },
{ label: '1:00 AM', value: 1 },
{ label: '1:15 AM', value: 1.25 },
{ label: '1:30 AM', value: 1.50 },
{ label: '1:45 AM', value: 1.75 }
];
#track options2 = [
{ label: '12:00 AM', value: 0 },
{ label: '12:15 AM', value: 0.25 },
{ label: '12:30 AM', value: 0.50 },
{ label: '12:45 AM', value: 0.75 },
{ label: '1:00 AM', value: 1 },
{ label: '1:15 AM', value: 1.25 },
{ label: '1:30 AM', value: 1.50 },
{ label: '1:45 AM', value: 1.75 }
];
handleChange1(event) {
// this.duration -= event.target.value;
this.value1 = event.target.value;
};
handleChange2(event) {
this.value2 = event.target.value;
this.duration = this.value2 - this.value1;
};
}
Before:
enter image description here
After:
enter image description here

As per the lightning-combobox documentation, you can use event.detail.value to grab the selected value in onchange.
The event.detail.value is passed as a string instead of an integer (e.g. '0.25' instead of 0.25). When you then set a string value instead of an integer, the option isn't found and it displays as undefined (Select progress).
You can either change the values to be strings:
const options = [
{ label: '12:00 AM', value: '0' },
{ label: '12:15 AM', value: '0.25' },
{ label: '12:30 AM', value: '0.50' },
{ label: '12:45 AM', value: '0.75' },
{ label: '1:00 AM', value: '1' },
{ label: '1:15 AM', value: '1.25' },
{ label: '1:30 AM', value: '1.50' },
{ label: '1:45 AM', value: '1.75' }
];
... or you can parse an integer in the handleChange() function:
handleChange(e) {
this.value = +e.detail.value; // One of the ways to convert str to int
};
Hope this helps. Happy coding.

Related

echarts stacked bar chart with time xaxis

Can someone check my chart options and suggest a way to make the time xaxis behave correctly? I've tried with timestamps, dates, timestamps / 1000 and nothing looks right
let sales = [
0,84,5,3,2,1,0,0,3,6
]
let listings = [
1,297,23,5,8,6,9,3,6,19
]
let ps = [
1663084060653,
1663089644329,
1663095228005,
1663100811680,
1663106395356,
1663111979032,
1663117562708,
1663123146384,
1663128730059,
1663134313735
]
let color = "red"
option = {
textStyle: {
color
},
legend: {
textStyle: {
color
},
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
type: 'time',
data: ps,
// axisLabel: {
// formatter: ts => new Date(ts).toTimeString().replace(/ .*/, '')
// }
}
],
yAxis: [
{
// type: 'value'
}
],
series: [
{
name: 'Sales',
type: 'bar',
stack: 'Ad',
emphasis: {
focus: 'series'
},
data: sales
},
{
name: "Listings",
type: 'bar',
stack: 'Ad',
emphasis: {
focus: 'series'
},
data: listings
}
]
}
Your series (listings & sales here) have to have a [date, value] format. Also, you'll have to remove data from xAxis as it will automatically follow the dates that are given in the series.
So, in your example :
//convert listings & sales to a list of [date, value]
listings = listings.map((value, index) => {
return [ps[index], value]
})
sales = sales.map((value, index) => {
return [ps[index], value]
})
xAxis: [
{
type: 'time',
//data: ps, <--- remove this line
}
],

vue #click change api request url

I'm very new to Vue and got stuck at this point.
The problem: I'm not getting my select with v-model to change api url to change data on html.
This is my html:
<div class="uk-width-1-2#s">
<select class="uk-select" id="form-stacked-select" v-model="selected" >
<option v-for="option in options" v-bind:value="option.value">
{{ option.text }}
</option>
</select>
</div>
<div v-else v-for="(cases, index) in cases_list" :key="index" >
<p>{{cases.deaths}} deaths.</p>
</div>
This is my Js:
const API_URL = 'https://covid19-brazil-api.now.sh/api/report/v1'
new Vue({
el: '#app',
data() {
return {
cases_list: [],
loading: true,
errored: false,
selected: 'df',
state: '',
number: '',
options: [
{ text: 'AC', value: 'ac' },
{ text: 'AL', value: 'al' },
{ text: 'AP', value: 'ap' },
{ text: 'AM', value: 'am' },
{ text: 'BA', value: 'ba' },
{ text: 'CE', value: 'ce' },
{ text: 'DF', value: 'df' },
{ text: 'ES', value: 'es' },
{ text: 'GO', value: 'go' },
{ text: 'MA', value: 'ma' },
{ text: 'MT', value: 'mt' },
{ text: 'MS', value: 'ms' },
{ text: 'MG', value: 'mg' },
{ text: 'PA', value: 'pa' },
{ text: 'PB', value: 'pb' },
{ text: 'PR', value: 'pr' },
{ text: 'PE', value: 'pe' },
{ text: 'PI', value: 'pi' },
{ text: 'RJ', value: 'rj' },
{ text: 'RN', value: 'rn' },
{ text: 'RS', value: 'rs' },
{ text: 'RO', value: 'ro' },
{ text: 'RR', value: 'rr' },
{ text: 'SC', value: 'sc' },
{ text: 'SP', value: 'sp' },
{ text: 'SE', value: 'se' },
{ text: 'TO', value: 'to' }
],
}
},
mounted() {
this.getCases();
},
methods: {
getCases() {
axios
.get(API_URL)
.then((response) => {
this.cases_list = response.data.data;
console.log(response.data.data);
})
.catch(error => {
console.log(error)
this.errored = true
})
.finally(() => this.loading = false)
}
}
})
My select option link to options array where I have texts and values, and every value should add on end of api url a 'uf/${option}' when selected...
Like: const API_URL = 'https://covid19-brazil-api.now.sh/api/report/v1' + 'uf/%{option}';
I'm very confused on how I make this select working. I was not able to find on vue documentation
You have to configure the URL before Axios call.
const API_URL = 'https://covid19-brazil-api.now.sh/api/report/v1/brazil'
new Vue({
el: '#app',
data() {
return {
cases_list: [],
loading: true,
errored: false,
selected: 'df',
state: '',
number: '',
options: [{
text: 'AC',
value: 'ac'
},
{
text: 'AL',
value: 'al'
},
{
text: 'AP',
value: 'ap'
},
{
text: 'AM',
value: 'am'
},
{
text: 'BA',
value: 'ba'
},
{
text: 'CE',
value: 'ce'
},
{
text: 'DF',
value: 'df'
},
{
text: 'ES',
value: 'es'
},
{
text: 'GO',
value: 'go'
},
{
text: 'MA',
value: 'ma'
},
{
text: 'MT',
value: 'mt'
},
{
text: 'MS',
value: 'ms'
},
{
text: 'MG',
value: 'mg'
},
{
text: 'PA',
value: 'pa'
},
{
text: 'PB',
value: 'pb'
},
{
text: 'PR',
value: 'pr'
},
{
text: 'PE',
value: 'pe'
},
{
text: 'PI',
value: 'pi'
},
{
text: 'RJ',
value: 'rj'
},
{
text: 'RN',
value: 'rn'
},
{
text: 'RS',
value: 'rs'
},
{
text: 'RO',
value: 'ro'
},
{
text: 'RR',
value: 'rr'
},
{
text: 'SC',
value: 'sc'
},
{
text: 'SP',
value: 'sp'
},
{
text: 'SE',
value: 'se'
},
{
text: 'TO',
value: 'to'
}
],
}
},
mounted() {
this.getCases();
},
watch: {
selected: function(val) {
this.getCases()
},
},
methods: {
getCases() {
console.log(API_URL + '/uf/' + this.selected);
axios
.get(API_URL + '/uf/' + this.selected)
.then((response) => {
this.cases_list = response.data;
console.log(response.data);
})
.catch(error => {
console.log(error)
this.errored = true
})
.finally(() => this.loading = false)
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js" integrity="sha512-VZ6m0F78+yo3sbu48gElK4irv2dzPoep8oo9LEjxviigcnnnNvnTOJRSrIhuFk68FMLOpiNz+T77nNY89rnWDg==" crossorigin="anonymous"></script>
<div id='app' class="uk-width-1-2#s">
<select class="uk-select" id="form-stacked-select" v-model="selected">
<option v-for="option in options" v-bind:value="option.value">
{{ option.text }}
</option>
</select>
</div>

Pre-checked checkbox in Bootbox

I'm using Bootbox and want to have one of the check boxes pre-selected. For example:
bootbox.prompt({
title: 'What would you like on your pizza?',
inputType: 'checkbox',
inputOptions: [
{
text: 'pepperoni',
value: '1',
},
{
text: 'mushrooms',
value: '2',
},
{
text: 'onions',
value: '3',
}
],
callback: function (result) {
console.log(result);
};
Lets say that I want to have the first item in the array, which is pepperoni, selected as a default. Is it possible to do this using Bootbox? Thanks in advance.
You need to add the value option to prompt.
For a single checked option (https://jsfiddle.net/j7wgncsf/):
bootbox.prompt({
title: 'What would you like on your pizza?',
inputType: 'checkbox',
value: '1', // <----- this
inputOptions: [
{
text: 'pepperoni',
value: '1',
},
{
text: 'mushrooms',
value: '2',
},
{
text: 'onions',
value: '3',
}
],
callback: function (result) {
console.log(result);
}
});
Or, to have multiple options checked, use an array (https://jsfiddle.net/yasok05p/):
bootbox.prompt({
title: 'What would you like on your pizza?',
inputType: 'checkbox',
value: ['1', '2'],// <----- this
inputOptions: [
{
text: 'pepperoni',
value: '1',
},
{
text: 'mushrooms',
value: '2',
},
{
text: 'onions',
value: '3',
}
],
callback: function (result) {
console.log(result);
}
});

Gantt chart to preview project status

so, how do i achieve this in highcharts? do anyone have a close JSfiddle or code for it?
so, this is the code i have tried so far, what should i update to achieve my visual,
help would be appreciated!! thanks in advance
var projects = [{
name: 'Project 1',
intervals: []
}, {
name: 'Project 2',
intervals: [{ // From-To pairs
froam: Date.UTC(2010, 5, 21),
to: Date.UTC(2015, 5, 21),
label: 'Project 2',
tooltip_data: 'this data'
}]
}, {
name: 'Project 3',
intervals: [{ // From-To pairs
from: Date.UTC(2011, 05, 16),
to: Date.UTC(2012, 03, 21),
label: 'Project 3',
tooltip_data: 'this data'
}, {
from: Date.UTC(2013, 07, 09),
to: Date.UTC(2015, 05, 22),
label: 'Project 3',
tooltip_data: 'this data'
}]
}, {
name: 'Project 9',
intervals: [{ // From-To pairs
from: Date.UTC(2013, 06, 17),
to: Date.UTC(2014, 04, 21),
label: 'Category 9',
tooltip_data: 'this data'
}, {
from: Date.UTC(2015, 01, 22),
to: Date.UTC(2015, 05, 22),
label: 'Category 9',
tooltip_data: 'this data'
}]
}];
var series = [];
$.each(projects.reverse(), function (i, task) {
var item = {
name: task.name,
data: []
};
$.each(projects.intervals, function (j, interval) {
item.data.push({
x: interval.from,
y: i,
label: interval.label,
from: interval.from,
to: interval.to,
tooltip_data: interval.tooltip_data
}, {
x: interval.to,
y: i,
from: interval.from,
to: interval.to,
tooltip_data: interval.tooltip_data
});
// add a null value between intervals
if (projects.intervals[j + 1]) {
item.data.push(
[(interval.to + projects.intervals[j + 1].from) / 2, null]
);
}
});
series.push(item);
});
// create the chart
var chart = new Highcharts.Chart({
chart: {
renderTo: 'aod-projectssummry-chart'
},
title: {
text: 'Project History'
},
xAxis: {
type: 'datetime'
},
yAxis: {
visible : false,
min: 0,
max: 8,
tickInterval: 1,
tickPixelInterval: 200,
labels: {
style: {
color: '#525151',
font: '12px Helvetica',
fontWeight: 'bold'
},
/* formatter: function() {
if (tasks[this.value]) {
return tasks[this.value].name;
}
}*/
},
startOnTick: false,
endOnTick: false,
title: {
text: 'Criteria'
},
minPadding: 0.2,
maxPadding: 0.2,
fontSize: '15px'
},
legend: {
enabled: false
},
tooltip: {
formatter: function () {
return '<b>' + tasks[this.y].name + '</b><br/>' + this.point.options.tooltip_data + '<br>' +
Highcharts.dateFormat('%m-%d-%Y', this.point.options.from) +
' - ' + Highcharts.dateFormat('%m-%d-%Y', this.point.options.to);
}
},
plotOptions: {
line: {
lineWidth: 10,
marker: {
enabled: false
},
dataLabels: {
enabled: true,
align: 'left',
formatter: function () {
return this.point.options && this.point.options.label;
}
}
}
},
series: series
});

ExtJS 4 ComboBox multiSelect display number of selected values

I am writing a POC and my client wishes to display the number of selected values underneath a multi-select combo box.
I can get the number of values from the select event listener but wanted to encapsulate the functionality in the component itself rather than have DIV where i perform a DOM update.
The code for the multi-select combo box is as follows:
Ext.onReady(function () {
// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data: [{
name: 'ALABAMA',
abbreviation: 'AL'
}, {
name: 'ALASKA',
abbreviation: 'AK'
}, {
name: 'AMERICAN SAMOA',
abbreviation: 'AS'
}, {
name: 'ARIZONA',
abbreviation: 'AZ'
}, {
name: 'ARKANSAS',
abbreviation: 'AR'
}, {
name: 'CALIFORNIA',
abbreviation: 'CA'
}, {
name: 'COLORADO',
abbreviation: 'CO'
}, {
name: 'CONNECTICUT',
abbreviation: 'CT'
}, {
name: 'DELAWARE',
abbreviation: 'DE'
}, {
name: 'DISTRICT OF COLUMBIA',
abbreviation: 'DC'
}, {
name: 'FEDERATED STATES OF MICRONESIA',
abbreviation: 'FM'
}, {
name: 'FLORIDA',
abbreviation: 'FL'
}, {
name: 'GEORGIA',
abbreviation: 'GA'
}, {
name: 'GUAM',
abbreviation: 'GU'
}, {
name: 'HAWAII',
abbreviation: 'HI'
}, {
name: 'IDAHO',
abbreviation: 'ID'
}, {
name: 'ILLINOIS',
abbreviation: 'IL'
}, {
name: 'INDIANA',
abbreviation: 'IN'
}, {
name: 'IOWA',
abbreviation: 'IA'
}, {
name: 'KANSAS',
abbreviation: 'KS'
}, {
name: 'KENTUCKY',
abbreviation: 'KY'
}, {
name: 'LOUISIANA',
abbreviation: 'LA'
}, {
name: 'MAINE',
abbreviation: 'ME'
}, {
name: 'MARSHALL ISLANDS',
abbreviation: 'MH'
}, {
name: 'MARYLAND',
abbreviation: 'MD'
}, {
name: 'MASSACHUSETTS',
abbreviation: 'MA'
}, {
name: 'MICHIGAN',
abbreviation: 'MI'
}, {
name: 'MINNESOTA',
abbreviation: 'MN'
}, {
name: 'MISSISSIPPI',
abbreviation: 'MS'
}, {
name: 'MISSOURI',
abbreviation: 'MO'
}, {
name: 'MONTANA',
abbreviation: 'MT'
}, {
name: 'NEBRASKA',
abbreviation: 'NE'
}, {
name: 'NEVADA',
abbreviation: 'NV'
}, {
name: 'NEW HAMPSHIRE',
abbreviation: 'NH'
}, {
name: 'NEW JERSEY',
abbreviation: 'NJ'
}, {
name: 'NEW MEXICO',
abbreviation: 'NM'
}, {
name: 'NEW YORK',
abbreviation: 'NY'
}, {
name: 'NORTH CAROLINA',
abbreviation: 'NC'
}, {
name: 'NORTH DAKOTA',
abbreviation: 'ND'
}, {
name: 'NORTHERN MARIANA ISLANDS',
abbreviation: 'MP'
}, {
name: 'OHIO',
abbreviation: 'OH'
}, {
name: 'OKLAHOMA',
abbreviation: 'OK'
}, {
name: 'OREGON',
abbreviation: 'OR'
}, {
name: 'PALAU',
abbreviation: 'PW'
}, {
name: 'PENNSYLVANIA',
abbreviation: 'PA'
}, {
name: 'PUERTO RICO',
abbreviation: 'PR'
}, {
name: 'RHODE ISLAND',
abbreviation: 'RI'
}, {
name: 'SOUTH CAROLINA',
abbreviation: 'SC'
}, {
name: 'SOUTH DAKOTA',
abbreviation: 'SD'
}, {
name: 'TENNESSEE',
abbreviation: 'TN'
}, {
name: 'TEXAS',
abbreviation: 'TX'
}, {
name: 'UTAH',
abbreviation: 'UT'
}, {
name: 'VERMONT',
abbreviation: 'VT'
}, {
name: 'VIRGIN ISLANDS',
abbreviation: 'VI'
}, {
name: 'VIRGINIA',
abbreviation: 'VA'
}, {
name: 'WASHINGTON',
abbreviation: 'WA'
}, {
name: 'WEST VIRGINIA',
abbreviation: 'WV'
}, {
name: 'WISCONSIN',
abbreviation: 'WI'
}, {
name: 'WYOMING',
abbreviation: 'WY'
}]
});
// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
labelAlign: 'top',
labelPad: 10,
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
editable: false,
displayField: 'name',
valueField: 'abbreviation',
renderTo: Ext.getBody(),
multiSelect: true,
width: 400,
displayTpl: '<tpl for=".">' +
'{name}' +
'<tpl if="xindex < xcount">, </tpl>' +
'</tpl>',
listConfig: {
itemTpl: '{name} <div class="chkbox"></div>'
},
listeners: {
select: function (combo, records) {
console.log(records.length);
}
}
});
});
Is there any easy way to achieve this?
You can write a simple plugin for combobox. Then it can be assigned to any combobox of your application.
For example:
Ext.define('comboSelectedCount', {
alias: 'plugin.selectedCount',
init: function(combo) {
var fl = combo.getFieldLabel();
combo.on({
'select': function(me, records) {
me.setFieldLabel(fl + ' (' + records.length + ' selected)');
},
'beforedeselect': function(me) {
me.setFieldLabel(fl);
}
});
}
});
And in your combo:
plugins: ['selectedCount'],
See live example on jsfiddle