vue #click change api request url - rest

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>

Related

How to pass the value of input to the next view of a modal in slack bolt framework?

I'm building a Slack API using bolt (on glitch). I'm new to this so and not sure about how to do this particular idea.
Using a slash command I open a modal that lists three radio inputs and has an action button that will use client.views.update to present a multi-line input.
I would like the option chosen to be the initial value of the multi-line code.
// this is required: github.com/slackapi/bolt
app.command("/slashcommand", async ({ ack, payload, context }) => {
// Acknowledge the command request
ack();
try {
const result = app.client.views.open({
token: context.botToken,
// Pass a valid trigger_id within 3 seconds of receiving it
trigger_id: payload.trigger_id,
// View payload
view: {
type: "modal",
callback_id: 'modal_1',
title: {
type: "plain_text",
text: "Initiate Feedback",
emoji: true
}, /*
submit: {
type: "plain_text",
text: "Submit",
emoji: true
}, */
close: {
type: "plain_text",
text: "Cancel",
emoji: true
},
blocks: [
{
type: "context",
elements: [
{
type: "mrkdwn",
text:
"Modal first view"
}
]
},
{
type: "divider"
},
{
type: "section",
block_id: 'radio_block',
text: {
type: "mrkdwn",
text: "Select from one of the following options:"
},
accessory: {
type: "radio_buttons",
action_id: 'radio_input',
initial_option: {
text: {
type: "plain_text",
text: "One"
},
value: "one",
description: {
type: "plain_text",
text: "describe one"
}
},
options: [
{
text: {
type: "plain_text",
text: "One"
},
value: "one",
description: {
type: "plain_text",
text: "describe one"
}
},
{
text: {
type: "plain_text",
text: "Two"
},
value: "two",
description: {
type: "plain_text",
text: "describe two"
}
},
{
text: {
type: "plain_text",
text: "Three"
},
value: "three",
description: {
type: "plain_text",
text: "describe three"
}
}
]
}
},
{
type: "actions",
elements: [
{
type: "button",
text: {
type: "plain_text",
text: "Next",
emoji: true
},
action_id: "next_1"
}
]
}
]
}
});
console.log(result);
} catch (error) {
console.error(error);
}
});
// Listen for a button invocation with action_id `next_1` (assume it's inside of a modal)
app.action("next_1", async ({ ack, body, context }) => {
// VALUE FROM RADIO INPUT
// const val = Radio input value;
// Acknowledge the button request
ack();
try {
const result = app.client.views.update({
token: context.botToken,
// Pass the view_id
view_id: body.view.id,
// View payload with updated blocks
view: {
type: "modal",
// View identifier
callback_id: 'feed_1',
title: {
type: "plain_text",
text: "Share Feedback: message"
},
blocks: [
{
type: "section",
text: {
type: "plain_text",
text: 'You choose '
}
},
{
type: "input",
element: {
type: "plain_text_input",
// HERE IS WHERE THE RADIO OPTION GOES
initial_value: `One `,
multiline: true
},
label: {
type: "plain_text",
text: "Message",
emoji: true
}
}
],
submit: {
type: "plain_text",
text: "Submit"
}
}
});
console.log(result);
} catch (error) {
console.error(error);
}
});
Ok figured this out finally!
1) make sure your radio buttons are not in any input blocks!
2) output your returned payload in your action using body.actions
once you see what your returning it will be easier to target that value.
'''
app.action("next_1", async ({ ack, body, context }) => {
// Result of option selected
const val = JSON.stringify(body['actions'][0]);
// see the values
console.log(val);
// Acknowledge the button request
ack();
});
'''
Further details: https://api.slack.com/reference/interaction-payloads/actions

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);
}
});

Not able to get reference to form in sencha

I am trying reset a form, on click of button.
The button's functionality is defined in file seperate controller file.
But on clicking button reset i get error
"Uncaught TypeError: Object form1orig has no method 'reset' "
Controller
Ext.define('myapp.controller.form1', {
extend: 'Ext.app.Controller',
requires: [
'myapp.view.form1'
],
config: {
refs: {
form1orig: '#pressc',
form1Submit: 'button[action=sub]',
form1Reset: 'button[action=res]'
},
control: {
'form1Reset' : {
tap: 'onForm1Reset'
},
'form1Submit' : {
tap: 'onForm1Submit'
}
}
},
onForm1Reset: function(button){
'form1orig'.reset();
console.log('Tapped reset');
},
onForm1Submit: function(button){
console.log('Tapped submit');
}
});
View
Ext.define('myapp.view.form1', {
extend: 'Ext.form.Panel',
requires: [
'Ext.form.FieldSet',
],
xtype: 'form1Me',
id: 'form1Me',
config: {
items: [
{
xtype: 'fieldset',
id: 'pressc',
instructions: 'Please enter the information above.',
defaults: {
labelWidth: '35%'
},
items: [
{
xtype:'textfield',
name: 'name',
label: 'Name',
id: 'eman',
placeHolder: 'Name'
},
{
xtype: 'textareafield',
name : 'Prescription',
id: 'pres',
label: 'Prescription',
placeHolder: 'Enter your prescription here...'
}
]
},
{
xtype: 'container',
defaults: {
xtype: 'button',
style: 'margin: .5em',
flex : 1
},
layout: {
type: 'hbox'
},
items: [
{
text: 'Submit',
id: 'subMe',
action: 'sub',
scope: this,
hasDisabled: false
//handler: function(btn){
/*var presscForm = Ext.getCmp('presscForm');
presscForm.submit({
url: '../../result.php',
method: 'POST',
success: function() {
alert('Thamk you for using our service');
}
});*/
//}
},
{
text: 'Reset',
id: 'resMe',
action: 'res'
/*handler: function(){
Ext.getCmp('form1Me').reset();
}*/
}
]
}
]
}
});
Help
You should do something like:
var form = Ext.ComponentQuery.query('form1Me');
form.reset();

Sencha touch nested list no data

I am new for sencha touch. I using mvc method. Please see my code below
Main.js
Ext.define('test.view.Main', {
extend: 'Ext.tab.Panel',
xtype: 'main',
requires: [
'Ext.TitleBar',
'Ext.Video',
'Ext.dataview.NestedList'
],
config: {
tabBarPosition: 'bottom',
items: [
{
title: 'Welcome',
iconCls: 'home',
styleHtmlContent: true,
scrollable: true,
items: {
docked: 'top',
xtype: 'titlebar',
title: 'Welcome to Sencha Touch 2'
},
html: [
"You've just generated a new Sencha Touch 2 project. What you're looking at right now is the ",
"contents of <a target='_blank' href=\"app/view/Main.js\">app/view/Main.js</a> - edit that file ",
"and refresh to change what's rendered here."
].join("")
},
{
title: 'Get Started',
iconCls: 'action',
items: [
{
docked: 'top',
xtype: 'titlebar',
title: 'Getting Started'
},
{
xtype: 'nestedlist',
}
]
}
]
}
});
Nestedlist.js
Ext.define('bluebutton.view.NestedList', {
extend: 'Ext.NestedList',
xtype: 'nestedlist',
requires: [
'Ext.field.Select',
'Ext.field.Search',
'Ext.plugin.ListPaging',
'Ext.plugin.PullRefresh',
],
config: {
store : { xclass : 'Test.store.data'},
detailContainer: detailContainer,
detailCard: true,
},
});
Test.store.data
Ext.define('Test.store.data', {
extend: 'Ext.data.TreeStore',
config: {
model: 'Test.model.data',
defaultRootProperty: 'items',
root: {
items: [
{
text: 'Drinks',
items: [
{
text: 'Water',
items: [
{ text: 'Still', leaf: true },
{ text: 'Sparkling', leaf: true }
]
},
{ text: 'Soda', leaf: true }
]
},
{
text: 'Snacks',
items: [
{ text: 'Nuts', leaf: true },
{ text: 'Pretzels', leaf: true },
{ text: 'Wasabi Peas', leaf: true }
]
}
]
}
}
});
model.js
Ext.define('Test.model.data', {
extend: 'Ext.data.Model',
config: {
fields: ['text']
}
});
But nested list no able to get the data. I get empty list. Any solution?
If you are providing inline data in store shouldn't it be data attribute instead of root?
Ext.define('Test.store.data', {
extend: 'Ext.data.TreeStore',
config: {
model: 'Test.model.data',
defaultRootProperty: 'items',
data: {
items: [
{
text: 'Drinks',
items: [
{
text: 'Water',
items: [
{ text: 'Still', leaf: true },
{ text: 'Sparkling', leaf: true }
]
},
{ text: 'Soda', leaf: true }
]
},
{
text: 'Snacks',
items: [
{ text: 'Nuts', leaf: true },
{ text: 'Pretzels', leaf: true },
{ text: 'Wasabi Peas', leaf: true }
]
}
]
}
}
});

Can't login to a web application through sencha app on clicking 'Sign in' button

This is my view
Ext.define("TimeSheet.view.Tracktime", {
extend: "Ext.form.Panel",
requires: ["Ext.form.FieldSet", "Ext.field.Text", "Ext.Button","Ext.Label", "Ext.field.Email", "Ext.field.Password","Ext.MessageBox", "Ext.Img"],
alias: "widget.tracktimeview",
config:{
id: 'entrypage',
fullscreen: true,
url: 'timesheet.ajatus.in/check.php',
//standardSubmit: false,
method: 'GET',
layout: {
centered: true,
},
defaults: {
styleHtmlContent: true,
//cls: 'backfield'
},
cls: 'panelBackground',
items: [{
xtype: 'fieldset',
id: 'loginfield',
autoComplete: true,
scrollable: false,
cls: 'formfield',
items: [{
xtype: 'image',
src: 'tracktime.png',
height: '60px',
cls: 'track'
},
{
xtype: 'textfield',
name : 'name',
label: 'tracktime/'
},
{
xtype: 'textfield',
name : 'uname',
allowBlank:false,
placeHolder: "User name"
},
{
xtype: 'passwordfield',
name : 'password',
allowBlank:false,
placeHolder: 'Password'
}
]
},{
xtype: 'button',
id: 'loginbtn',
cls: 'enter',
text: 'Sign in',
ui: 'confirm',
height: "50px",
}],
control: ({
'#loginbtn': {
tap: function() {
}
}
}),
},});
THIS IS CONTROLLER
Ext.define("TimeSheet.controller.Track", {
extend: "Ext.app.Controller",
config: {
refs: {
trackTimeView: "tracktimeview",
selector: '#tracktimeview',
addentryView: "addentryview",
selector: '#addentryview',
entryPage: '#entrypage',
loginBtn: '#loginbtn'
},
control:{
loginBtn: {
tap: "onLoginBtn"
},
onloginbtn: {
tap: function(btn) {
var form = Ext.getCmp('entry');
//var values = entry.getValues();
entry.submit({
method:'POST',
url: 'xxxxxxxx/check.php',
params: values,
success: function(response){
var text = response.responseText;
Ext.Msg.alert('Success', text);
},
failure : function(response) {
Ext.Msg.alert('Error','Error while submitting the form');
console.log(response.responseText);
}
});
}
},
}
},
onLoginBtn: function() {
console.log("onLoginBtn");
var values = TimeSheet.views.tracktimeview.entrypage.getValues();
TryLogin(values['uname'], values['password']);
},
launch: function () {
this.callParent(arguments);
console.log("launch");
},
init: function () {
this.callParent(arguments);
console.log("init");
}});