how can I implement 3 dependent selects with autoform in meteor?
Here is an example of what I need to achieve http://www.ajaxray.com/Examples/depend.html
Thanks in advance for any help
You could add an event listener to your select and when it changes, update the select helper for the next select (or all select's) you have in your form. It would be something similar to the following example, but update the "options" object depending on what was selected by a different select input.
http://autoform.meteor.com/select
This is the way I solved it. However for the third select to return the selected value once the first select is updated I had to use JQuery. This might help to someone in need of something similar. But if there is a better way to do it please let me know.
Organizaciones = new Mongo.Collection('organizaciones');
Organizaciones.attachSchema(new SimpleSchema({
provincia: {
type: String,
label: 'Provincia',
autoform: {
type: 'select',
firstOption: '',
options: function () {
return DPA.find({grupo: 'Provincia'}).map(function (dpa) {
return {label: dpa.descripcion, value: dpa.codigo};
});
}
}
},
canton: {
type: String,
label: 'Cantón',
autoform: {
type: 'select',
firstOption: '',
options: function () {
var codigoProvincia = AutoForm.getFieldValue('provincia');
var cantones = new RegExp('^' + codigoProvincia + '[\d]{2}$');
return DPA.find({codigo: {$regex: cantones}}).map(function (dpa) {
return {label: dpa.descripcion, value: dpa.codigo};
});
}
}
},
parroquia: {
type: String,
label: 'Parroquia',
autoform: {
type: 'select',
firstOption: '',
options: function () {
$('#provincia').change(function() {
$('#parroquia option[value!=""]').remove();
});
var codigoCanton = AutoForm.getFieldValue('canton');
var parroquias = new RegExp('^' + codigoCanton + '[\d]{2}$');
return DPA.find({codigo: {$regex: parroquias}}).map(function (dpa) {
return {label: dpa.descripcion, value: dpa.codigo};
});
}
}
}
}));
Related
I have a form page and I use it for both create and update
My form fields are like this;
enter image description here
content: (...)
i18n: (...)
image: (...)
name: (...)
orderIndex: (...)
position: (...)
I can successfully submit a request.
When we come to the update process, I get the data in this way and sync it. I'm getting extra data (this.myForm = response.data)
When I send an update request I just want the form fields to go but it goes like this
I don't want to send createdAt, deleted, updatedAt, _id fields
enter image description here
content: (...)
createdAt: (...)
deleted: (...)
i18n: (...)
image: (...)
isEnabled: (...)
name: (...)
orderIndex: (...)
position: (...)
updatedAt: (...)
_id: (...)
How can I submit only form fields? (I am using element-ui btw)
Is there something like this.$refs.myForm.fields or this.$refs.myForm.values I couldn't find it
For example Angular reactive form has something like this --> this.testimonialForm.patchValue(response.data);
data() {
return {
id: null,
testimonialForm: {
name: '',
position: '',
content: '',
orderIndex: '',
i18n: '',
image: {
path: ''
}
}
}
},
computed: {
...mapState({
testimonialData: state => state.testimonial.testimonial
})
},
created() {
if (this.$route.params.id) {
this.id = this.$route.params.id
this.fnGetTestimonialInfo(this.id)
}
},
methods: {
fnCreateTestimonial() {
this.$store.dispatch('testimonial/create', this.testimonialForm).then(() => {
this.$router.push('/testimonial/list')
})
},
fnUpdateTestimonial() {
const data = { id: this.id, data: this.testimonialForm }
this.$store.dispatch('testimonial/update', data).then(() => {
this.$router.push('/testimonial/list')
})
},
fnGetTestimonialInfo(id) {
this.$store.dispatch('testimonial/get', id).then(() => {
this.testimonialForm = this.testimonialData
})
},
}
Solved like this :
const pick = require('lodash/pick')
const formKeys = Object.keys(this.testimonialForm)
this.testimonialForm = pick(this.testimonialData, formKeys)
Thanks to #gguney for the guidance.
First of all, You have to fetch your object from backend. You do not neet to your store.
Just use axios to fetch your resource.
axios.get('/testimonial/get/' + id)
.then(function (response) {
this.testimonialForm = response.data.testimonial
console.log(response);
})
.catch(function (error) {
console.log(error);
});
You can use your inputs like:
<el-input
v-model="testimonialForm.name"
:placeholder="$t('form.name')"
name="name"
type="text"
/>
Then send your testimonialForm to your backend via axios.
You can add underscorejs to your project and use this function
_.pick(testimonialForm, 'name', 'otherField');
Good Morning.
To work with wfs layer is it better to use leaflet or openlayers?
I have a code with openlayers that returns WFS from the geoserver. But I'm not able to show the attributes in popup. can anybody help me?
Thanks
You can try ol-ext ol/Overlay/PopupFeature to display feature attributes in a popup.
See example: https://viglino.github.io/ol-ext/examples/popup/map.popup.feature.html
Following the example of https://viglino.github.io/ol-ext/examples/popup/map.popup.feature.html, I have this code where my WFS layer contains the id and name attributes, however, it doesn't show anything in the popup
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'http://localhost:8080/geoserver/teste/wfs?service=WFS&' +
version=1.1.0&request=GetFeature&typename=teste:MYLAYER&' +
'outputFormat=application/json&srsname=EPSG:4326&' +
'bbox=' + extent.join(',') + ',EPSG:4326';
},
strategy: ol.loadingstrategy.bbox
});
var vector = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});
var layers = [
new ol.layer.Tile({source: new ol.source.OSM()}),
vector,
];
var map = new ol.Map({
layers: layers,
interactions: ol.interaction.defaults({ altShiftDragRotate:false, pinchRotate:false }),
target: 'map',
view: new ol.View({
center: ol.proj.fromLonLat([-46.444137, -23.713596]),
zoom: 12
})
});
var select = new ol.interaction.Select({
hitTolerance: 5,
multi: true,
condition: ol.events.condition.singleClick
});
map.addInteraction(select);
var popup = new ol.Overlay.PopupFeature({
popupClass: 'default anim',
select: select,
canFix: true,
template: {
title:
function(f) {
return f.get('nome')+' ('+f.get('id')+')';
},
attributes: // [ 'id', 'nome' ]
{
'nome': { title: 'Nome' },
'id': { title: 'Id' },
}
}
});
map.addOverlay (popup);
This is the popup code. I have 3 layers: layer1, layer2 and layer3.
For layer1, ID I want to show as ID. For layer2, I want to show ID as CODE and for other layers I don't want to show ID attribute.
How should I change the template? Thanks
var popup = new ol.Overlay.PopupFeature({
popupClass: 'default anim',
select: select_interaction,
canFix: true,
template: {
title:
function(f) {
return f.get('NAME')+' ('+f.get('ID')+')';
},
attributes:
{
'ID': { title: 'ID' },
// with prefix and suffix
'POP': {
title: 'População', // attribute's title
before: '', // something to add before
format: ol.Overlay.PopupFeature.localString(), // format as local string
after: ' hab.' // something to add after
},
}
}
});
#user12538529
You have to create a function and return the template for each case:
// Create templates
var templateID = { ... };
var templateCODE = { ... };
// Popup with a template function
var popup = new ol.Overlay.PopupFeature({
popupClass: 'default anim',
select: select_interaction,
canFix: true,
template: function(feature) {
var prop = feature.getProperties();
// Test if has property ID
if (prop.hasOwnProperty('ID')) return templateID;
// or property CODE
else if (prop.hasOwnProperty('CODE')) return templateCODE;
}
});
I have a problem with migrating the plugin from tinymce 4 to tinymka 5. The console tells me "Uncaught (in promise) TypeError: btn.active is not a function"
I can not find an equivalent for tinymce 5. Can someone replace it?
Code below:
tinymce.PluginManager.add('phonelink', function(editor, url) {
// Add a button that opens a window
var linkText = "";
var linkTitle = "";
var link = "";
// tinymce.DOM.loadCSS(url + '/css/phonelink.css');
editor.ui.registry.addButton('phonelink2', {
text: 'asddas',
icon: 'image-options',
onSetup: updateOnSelect,
onAction: onClickPhoneButton
});
// Adds a menu item to the tools menu
editor.ui.registry.addMenuItem('phonelink', {
text: 'asddas',
icon: 'image-options',
context: 'tools',
onAction: onClickPhoneButton,
onSetup: updateOnSelect
});
function onClickPhoneButton(){
editor.windowManager.open({
title: '123213123',
body: {
type: 'panel',
items: [
{type: 'input', name: 'phone', label: 'Teléfono', value: link},
{type: 'input', name: 'showtext', label: 'Texto a mostrar', value: linkText},
{type: 'input', name: 'title', label: 'Título', value: linkTitle}
]
},
buttons: [
{
text: 'Close',
type: 'cancel',
onclick: 'close'
},
{
type: 'submit',
name: 'submitButton',
text: 'Stwórz',
primary: true
}
],
onAction: function(e) {
alert('Toggle menu item clicked');
},
onSubmit: function(e) {
var data = e.getData();
var hrefLink = '<a title="' + data .title + '" href="tel:+34' + data .phone + '">' + data .showtext + '</a>';
if(link !== ''){
editor.setContent(hrefLink);
}else{
editor.insertContent(hrefLink);
}
e.close();
}
});
}
function updateOnSelect() {
var btn = this;
const editorEventCallback = function (e) {
var node = editor.selection.getNode();
var isTelLink = node.href !== undefined && node.href.indexOf('tel:+') !== -1
btn.active(isTelLink);
if(isTelLink){
link = node.href;
link = link.replace("tel:+34", "");
linkTitle = node.title;
linkText = node.text;
}
};
editor.on('NodeChange', editorEventCallback);
return function (btn) {
editor.off('NodeChange', editorEventCallback);
}
}
});
I searched the documentation for a replacement, but found nothing.
TinyMCE 5 no longer passes the button and menu instance via this. Instead it passes an API instance as the first parameter, so you'll want to change your updateOnSelect function to something like this:
function updateOnSelect(api) {
const editorEventCallback = function (e) {
var node = editor.selection.getNode();
var isTelLink = node.href !== undefined && node.href.indexOf('tel:+') !== -1
api.setActive(isTelLink);
if(isTelLink){
link = node.href;
link = link.replace("tel:+34", "");
linkTitle = node.title;
linkText = node.text;
}
};
editor.on('NodeChange', editorEventCallback);
return function (btn) {
editor.off('NodeChange', editorEventCallback);
}
}
You'll note var btn = this has been removed and that the API to set an item as active is setActive instead of active. This can be found in the documentation here: https://www.tiny.cloud/docs/ui-components/typesoftoolbarbuttons/#togglebutton and https://www.tiny.cloud/docs/ui-components/menuitems/#togglemenuitems (see the API section in both links).
In the above, you may have noticed both reference "Toggle" items. That's another change in TinyMCE 5, as different types of buttons/menu items have a separate registration API. So you'll also need to swap to using editor.ui.registry.addToggleButton and editor.ui.registry.addToggleMenuItem. More details about that can be found here if needed: https://www.tiny.cloud/docs/migration-from-4x/#customtoolbarbuttons
Here's an example fiddle showing the changes mentioned above: https://fiddle.tiny.cloud/B5haab.
Hopefully that helps!
i need help about a kendo autocomplete widget...
Maybe this is a stupid question, but i just can't reach the solution!!!
My kendoAutoComplete widget, gets data from a c# webservice:
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false)]
[WebMethod]
public string getComuniList()
{
using (PrintInvoicesDataContext context = new PrintInvoicesDataContext())
{
List<comuni_italia> comuni = new List<comuni_italia>();
comuni = context.comuni_italia.ToList();
var jsonStr = JsonConvert.SerializeObject(comuni, Formatting.Indented);
return jsonStr;
}
}
this method returns a long object array like this:
[ {id_comune: 1, des_comune: "Milano", cod_comune: "A130", cap_comune: "64022"},
{id_comune: 2, des_comune: "Torino", cod_comune: "A131", cap_comune: "64100"},
....
]
so, when i choose an item into the kendo autocomplete widget, on the select event, i need to save the whole selected object in a variable.
var comuneAutoComplete = $("#comune_w").kendoAutoComplete({
minLength: 3,
dataSource: dataSource,
placeholder: "Inserisci comune...",
dataTextField: "des_comune",
dataValueField: "id_comune"
}).data("kendoAutoComplete").bind("select", function (data) {
//here i want to save the object
var comune = ????????
});
so that i could get fields values like this:
var id_com = comune.id_comune;
var des_com = comune.des_comune;
..........
this is the model of the datasource:
model: {
fields: {
id: "id_comune",
id_comune: { type: "string" },
des_com: { type: "string" },
des_prv: { type: "string" },
des_reg: { type: "string" },
cod_com: { type: "string" },
cod_prv: { type: "string" },
cod_res: { type: "string" }
}
Is it possible??
hope someone can help me!
thanks in advance.
Getting the data from the dataSource for the selected item is:
var comuneAutoComplete = $("#comune_w").kendoAutoComplete({
minLength: 3,
dataSource: dataSource,
placeholder: "Inserisci comune...",
dataTextField: "des_comune",
dataValueField: "id_comune"
}).data("kendoAutoComplete").bind("select", function (data) {
//here i want to save the object
var comune = this.dataItem(e.item.index());
...
});
I have a textfield:
xtype: "fieldset",
items:[
{
xtype: "textfield",
name: "dateScanned",
label: "Datum",
disabled: true,
tpl: "{dateScanned:date('d/m/Y H:i')}" // <--- this dosn't work
}
]
My Store is:
fields: [
{ name: 'dateScanned', type: 'date', dateFormat: 'c' }
]
Why does the marked point not work?
How can I realize that the date is fomatted?
/*Override to allow textfields to format dates*/
Ext.override(Ext.field.Text, {
setValue: function (value) {
if (this.config.dateFormat && value) {
if (Ext.isDate(value)) {
value = Ext.Date.format(value, this.config.dateFormat);
}
else {
var d = new Date(value);
value = Ext.Date.format(d, this.config.dateFormat);
}
}
this.callSuper(arguments);
}
});
MyAppWhere do you insert that override up there?
If i add a new Text.js under app/field/Text.js and link it under require it doesn't work
SOLUTION
/*Override to allow textfields to format dates*/
Ext.define('MyApp.field.Text', {
override: 'Ext.field.Text',
setValue: function (value) {
if (this.config.dateFormat && value) {
if (Ext.isDate(value)) {
value = Ext.Date.format(value, this.config.dateFormat);
}
else {
var d = new Date(value);
value = Ext.Date.format(d, this.config.dateFormat);
}
}
this.callSuper(arguments);
}
});
You create a folder in your project Project/app/field/Text.js and put the code in
And then under requires add
requires: [
'MyApp.field.Text'
],
I have a solution:
dateFormat instead of tpl
xtype: "fieldset",
items:[
{
xtype: "datepickerfield",
name: "dateScanned",
label: "Datum",
disabled: true,
dateFormat: "d.m.Y H:i"
//tpl: "{dateScanned:date('d/m/Y H:i')}" // <--- this dosn't work
}
]
I don't know, but I believe to remember that it is important to set the double question marks.