ion range slider and modal: how to populate to and from before modal is shown - ion-range-slider

I am using ionrangeslider in a modal
<!-- The Modal -->
<div class="modal" id="myModal">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content" style="width: auto;margin: 0 auto">
<!-- Modal body -->
<div class="modal-body">
<input type="text" id="mySlider"/>
</div>
</div>
</div>
</div>
I get some values from ajax and after that i set the to and from for the slider like
$(document).ready(function () {
$('#mySlider').ionRangeSlider({
grid: false,
type: 'double',
min: 1,
max: 10,
force_edges: true,
drag_interval: true,
step: 1,
});
$.ajax({
url: "/get_schedule_for_zone/",
type: 'POST',
headers: { 'X-CSRFToken': csrftoken },
data: {"deviceassigned_id": parseInt(deviceassigned_id),"zone_number": parseInt(zone_number)},
success: function(res) {
$('#mySlider').data("ionRangeSlider").update({from: res.to})
$('#mySlider').data("ionRangeSlider").update({to: res.from})
$('$myModal').modal('show')
},
error : function(xhr,errmsg,err) {
console.log(err)
}
})
})
what i found it the modal open and then shows the slider without to and from, and then updated the to and from. the user can see that they are changing from nothing to some values
how to set them before i open the modal and show them there.

if your slider is inside a div, just hide it:
<div id="slider">
<input type="text" class="js-range-slider" id="test" name="my_range" value=""
data-min="40"
data-max="210"
data-from="{{row2.7}}"
data-grid="true"
data-hide-min-max="true"
data-postfix="'F"
data-type="double"
/>
</div>
$("#slider").hide();
and after displaying you modal, (or just before)
$("#slider").show();
other solution is to play with opacity

Related

Vue v-model/v-for doesn't update on mount, but after first manual change

I have a dropdown list "functions" that is filled with database entries and a dropdown list with 2 hardcoded entries. When the vue website is opened the dropdown list remains empty but as soon as I change the value of the other dropdown field the desired data from the database is available.
I'm a bit confused because I expected that adding "retrieveFunctions()" into the mounted() function would trigger the v-for, and even more confused that changing something in another select field suddenly triggers it.
The HTML code:
<template>
<div class="submit-form">
<div v-if="!submitted">
<div class="row">
<div class="col-sm-12">
<p><a style="width:500px" class="btn btn-info" data-toggle="collapse" href="#generalInformation" role="button" aria-expanded="true" >
General Information</a></p>
<div class="collaps show" id="generalInformation">
<!-- NAME -->
<div class="form-group">
<input placeholder="Name" type="text" class="form-control"
id="name" required v-model="component.name" name="name">
</div>
<!-- DOMAIN -->
<div class="input-group mb-3">
<div class="input-group-prepend">
<label style="width:100px" class="input-group-text" for="inputGroupDomain">Domain</label>
</div>
<select v-model="component.domain"
class="custom-select"
id="inputGroupDomain"
>
<option value="Power System">Power System</option>
<option value="ICT">ICT</option>
</select>
</div>
<!-- FUNCTION -->
<div class="input-group mb-3">
<div class="input-group-prepend">
<label style="width:100px" class="input-group-text" for="inputGroupFunction">Functions</label>
</div>
<select v-model="_function" class="custom-select" id="inputGroupFunction">
<option :class="{ active: index == currentIndex }"
v-for="(_function, index) in functions"
:key="index"
value= _function.name>
{{ _function.name }}
</option>
</select>
</div>
</div>
<p>
<button #click="saveComponent" class="btn btn-success">Add Component</button>
</p>
</div>
</div>
</div>
<div v-else>
<h4>Component was added succesfully!</h4>
<button class="btn btn-success" #click="newComponent">Proceed</button>
</div>
The script part:
<script>
import FunctionDataService from "../services/FunctionDataService";
export default {
name: "add-component",
data() {
return {
component: {
id: null,
name: "",
type: "",
domain: "",
},
submitted: false
};
},
methods: {
retrieveFunctions() {
FunctionDataService.getAll()
.then(response => {
this.functions = response.data;
console.log(response.data);
})
.catch(e => {
console.log(e);
});
},
refreshList() {
this.retrieveFunctions();
},
},
mounted() {
this.retrieveFunctions();
}
};
</script>
refreshList() {
this.retrieveFunctions();
},
},
mounted() {
this.retrieveFunctions();
}
};
</script>
State in the beginning: Dropdown list empty
State after selecting something in the upper dropdown list: Database entries are visible and correct
You need to initiate all responsive properties on the data return object with either a value (empty string, array, object, etc) or null. Currently it's missing the _function attribute used in the select v-model and the functions array used in the v-for. You can try to change the data to the following:
data() {
return {
_function: "",
functions: [],
component: {
id: null,
name: "",
type: "",
domain: "",
},
submitted: false
};
},

Click Event on Dynamically Generated Button Don't get fired in Vue

I am adding a button dynamically and attaching the click event but it doesn't seem to fire.
I see something similar on link below but its not exactly what I am looking for.
Vue: Bind click event to dynamically inserted content
let importListComponent = new Vue({
el: '#import-list-component',
data: {
files: [],
},
methods: {
// more methods here from 1 to 5
//6. dynamically create Card and Commit Button
showData: function (responseData) {
let self = this;
responseData.forEach((bmaSourceLog) => {
$('#accordionOne').append(`<div class="main-card mb-1 card">
<div class="card-header" id=heading${bmaSourceLog.bmaSourceLogId}>
${bmaSourceLog.fileName}
<div class="btn-actions-pane-right actions-icon-btn">
<input type="button" class="btn btn-outline-primary mr-2" value="Commit" v-on:click="commit(${bmaSourceLog.bmaSourceLogId})" />
<a data-toggle="collapse" data-target="#collapse${ bmaSourceLog.bmaSourceLogId}" aria-expanded="false" aria-controls="collapse${bmaSourceLog.bmaSourceLogId}" class="btn-icon btn-icon-only btn btn-link">
</a>
</div>
</div>
<div id="collapse${ bmaSourceLog.bmaSourceLogId}" class="collapse show" aria-labelledby="heading${bmaSourceLog.bmaSourceLogId}" data-parent="#accordionOne">
<div class="card-body">
<div id="grid${ bmaSourceLog.bmaSourceLogId}" style="margin-bottom:30px"></div>
</div>
</div>
</div>`);
});
},
//7. Commit Staging data
commit: function (responseData) {
snackbar("Data Saved Successfully...", "bg-success");
},
}});
I am adding button Commit as shown in code and want commit: function (responseData) to fire.
I was able to achieve this by pure Vue way. So my requirement was dynamically add content with a button and call a function from the button. I have achieved it like so.
Component Code
const users = [
{
id: 1,
name: 'James',
},
{
id: 2,
name: 'Fatima',
},
{
id: 3,
name: 'Xin',
}]
Vue.component('user-component', {
template: `
<div class="main-card mb-1 card">
<div class="card-header">
Component Header
<div class="btn-actions-pane-right actions-icon-btn">
<input type="button" class="btn btn-outline-primary mr-2" value="Click Me" v-on:click="testme(user.id)" />
</div>
</div>
<div class="card-body">
{{user.name}}
</div>
<div class="card-footer">
{{user.id}}
</div>
</div>
`
,props: {
user: Object
}
,
methods: {
testme: function (id) {
console.log(id);
}
}});
let tc = new Vue({
el: '#test-component',
data: {
users
},});
HTML
<div id="test-component">
<user-component v-for="user in users" v-bind:key="user.id" :user="user" />
</div>

Carousel not working in Vue js but working in simple php file

I am using owl.carousel in my vue app. But carousel is not showing up on the page. I have include (owl.carousel.min.css) and other relevant files(jquery,bootstrap) inside my index.html. These files can also be seen in network tab of the browser which mean files are loading but no carousel(or images) are seen.When I remove owl.carousel.min.css from index, it displays images used inside carousel on top of one another but no carousel. Any idea what the issue might be..??Thank you.
<div class="banner-slider">
<div class="container">
<div class="row">
<div class="carousel-wrap">
<div id="sync2" class="navigation-thumbs owl-
carousel">
<div class="item">
<img src="./images/bslide4.png">
<div class="details">
<p>Alex</p>
<small>Guitarist</small>
</div>
</div>
<div class="item">
<img src="./images/bslide1.png">
<div class="details">
<p>MIRA</p>
<small>Filmmaking</small>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
And
var sync1 = $(".slider");
var sync2 = $(".navigation-thumbs");
var thumbnailItemClass = '.owl-item';
var slides = sync1.owlCarousel({
video:true,
startPosition: 3,
items:1,
loop:true,
margin:10,
autoplay:true,
autoplayHoverPause:false,
nav: false,
dots: true,
responsive: {
0: {
items: 1,
loop:true
},
600: {
items: 1,
loop:true
},
1000: {
items: 1,
loop:true
}
}
}).on('changed.owl.carousel', syncPosition);

How to close Modal de Materialize CSS with Vue

I am trying to close a Modal of Materialize CSS if the validation is correct but I can not find the form.
The simplest thing was to do a type validation:
v-if = "showModal" and it works but leaves the background of the Modal and although click does not disappear. The background is a class named 'modal-overlay'
This is my code:
<i class="material-icons modal-trigger tooltipped" style="margin-left: 2px;
color:#ffc107; cursor:pointer;" #click="getById(article), fillSelectCategories(),
titleModal='Edit', type='edit'" data-target="modal1">edit</i>
I imported M from the JS file of MaterilizeCSS
import M from "materialize-css/dist/js/materialize.min";
Method:
update(){
var elem = document.querySelectorAll('.modal');
var instance = M.Modal.getInstance(elem);
console.log(instance)
That returns 'undefined'
I tried this too on the update() method:
var elem = document.querySelectorAll('.modal');
elem.close();
M.Modal.close()
I initialize the modal from mounted and it works fine but I can not close it at the moment I require it.
mounted(){
var elems = document.querySelectorAll('.modal');
var instances = M.Modal.init(elems, options);
}
But I know what else to try :(
It really is difficult to know why things aren't working for you without looking further into your code, but I've created this simple example to demonstrate how it could be done ..
new Vue({
el: "#app",
data: {
modalInstance: null,
closeAfterTimeElapsed: true,
seconds: 1
},
mounted() {
const modal = document.querySelector('.modal')
this.modalInstance = M.Modal.init(modal)
const select = document.querySelector('select');
M.FormSelect.init(select);
M.updateTextFields();
},
methods: {
handleClick() {
if (this.closeAfterTimeElapsed) {
setTimeout(() => { this.modalInstance.close() }, this.seconds * 1000)
}
}
}
})
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue#2.5.17/dist/vue.js"></script>
<div id="app">
<!-- Modal Trigger -->
<button #click="handleClick" data-target="modal1" class="btn modal-trigger">Modal</button>
<!-- Modal Structure -->
<div id="modal1" class="modal">
<div class="modal-content">
<h4>Modal Header</h4>
<p>A bunch of text</p>
</div>
<div class="modal-footer">
Agree
</div>
</div>
<br>
<br>
<div class="row">
<div class="input-field col s6">
<select v-model="closeAfterTimeElapsed">
<option :value="false">False</option>
<option :value="true">True</option>
</select>
<label>Close Modal After</label>
</div>
<div class="input-field col s6">
<input id="seconds" type="number" v-model="seconds">
<label for="seconds">Seconds</label>
</div>
</div>
</div>
See this JSFiddle

Bootbox with Aurelia

I know that I can directly add HTML forms via the message, however can I do something like:
message: document.getElementById('formContent').innerHTML?
Is this my DIV.
<div class="col-sm-6">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">Search For Options</label>
<input disabled.bind="readonly" type="text" class="form-control" value.bind="SearchForOptions">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">AND / OR</label>
<dropdown disabled.bind="readonly" options.bind="core.GetOptionsList()" value.bind="OptionId" selected.bind="OptionId" />
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<button click.trigger="cancelSearch()" class="btn btn-default" type="button">Cancel</button>
<button click.trigger="searchOptions()" class="btn btn-info" type="button" disabled.bind="!canSearch">Search</button>
</div>
</div>
</div>
core. GetOptionsList() - Aureila
import {Core} from 'admin/core';
#inject(Core)
constructor(core){
this.core = core;
}
UPDATE
Its pulling the content of the <div> however not the values from the DD
bootbox.dialog({
title: "This is a form in a modal.",
message: jQuery('#search').html(),
buttons: {
success: {
label: "Save",
className: "btn-success",
callback: function () {
//var name = $('#name').val();
//var answer = $("input[name='awesomeness']:checked").val()
//Example.show("Hello " + name + ". You've chosen <b>" + answer + "</b>");
}
}
}
});
UPDATE
addNew(){
bootbox.dialog({
title: "Search Options",
message: jQuery('#searchCriteria').html(),
buttons: {
cancel: {
label: 'Cancel',
className: 'btn btn-default'
},
confirm: {
label: 'Search',
className: 'btn-primary btn btn-info',
callback: function() {
var text = $("#SearchForOptions").val();
var dropdown = $("#OptionId").val();
alert(text);
alert(dropdown);
if (!text || !dropdown){
return false;
} else {
this.searchOptions(text, dropdown);
}
}
},
}
});
}
Sorry, I forgot to put this in my original question. dropdown is a custom element, which takes the following:
options: list of options
value: value of selected option
selected: value of selected option
My main issue is can I use aureila i.e. binding elements such as value.bind, or do I need to build my DD manually etc? As it currently looks like I cannot use any binding.