Vue.js Change placeholder in template dynamically - templates

I want change the placeholder in a template dynamically over the input of a textbox but it not work after change the value. Initial it work perfect.
Demo
https://jsfiddle.net/he4gx40g/
Update: Working example thanks #Roy J
https://jsfiddle.net/z3gbk0L2/
Example of the component (without the textbox logic)
<customValueComponent :item="config" :value="'ConfigValue1'" />
Code of the customValue component
customValueComponent: {
props: {
item: {
type: Object,
required: true
},
value: {
type: String,
required: true
}
},
watch: {
value: function (newVal, oldVal) { // watch it
console.log('Prop changed: ', newVal, ' | was: ', oldVal)
this.$options.template = '<div>{{ item.' + this.value + '}}</div>';
}
},
created: function () {
this.$options.template = '<div>{{ item.' + this.value + '}}</div>';
},
template: ''
}
Object
var config =
{
ConfigValue1: "Titanium",
ConfigValue2: "Gold",
ConfigValue3: "Silver",
ConfigValue4: "Bronze",
ConfigValue5: "Copper",
...
};

$options is read-only. This is not how you change values in a template. Vue updates values as they change. Your component definition should be
Vue.component('customvalue-component', {
props: {
item: {
type: Object,
required: true
},
value: {
type: String,
required: true,
}
},
template: '<div>{{value}}</div>'
});
And your binding on the component should be
<customvalue-component :item="config" :value="config[value1]" />

Related

How to conditionally pass in a picture AND a child component's string

a Vue newbie here. I am constructing a navbar-brand element as part of my navbar.
<template>
<!--Navbar-->
<navbar position="top" className="red">
<!-- Navbar brand -->
<navbar-brand></navbar-brand>
...
I would like it to display its child - a string passed in between the tags, if present AND a picture, if the prop.src is not empty. How do I do that - how do I condition the render function? The code is here:
import classNames from 'classnames';
export const props = {
tag: {
type: String,
default: "a"
},
src: {
type: String,
required: true
},
alt: {
type: String,
default: 'brand logo'
},
href: {
type: String,
default: '#'
},
className: {
type: String
}
};
export default {
functional: true,
props,
render(h, { props, data, children }) {
const dataObj = {
class: classNames(
'navbar-brand',
props.className ? props.className : ''
),
attrs: {
href: 'props.href'
}
};
const img = [
h('img', {
class: [],
attrs: {
src: props.src,
alt: props.alt
}
})
];
const
return h(props.tag, dataObj, img);
}
};
PLS HALP
Yours, Paco

how to parse false values in mustache

I am new to mustache. Have an object like
object = [{
name: 'A',
fields: { type: "string" }
},
{
name: 'B',
fields: { type: "boolean", default: false }
}]
I am passing that object to mustache template and I want generated code where default values are also shown.
Code:
{{#object}}
var {{name}}: {{#fields}} {{type}} {{^default}} = {{default}} {{/default}}{{/fields}}
{{/object}}
But I am not able to get the expected output from above code.
Expected Output:
var A: string
var B: boolean = false
If default were the string "false" it would (almost) work. You've currently got the equivalent to:
default = false
if (!default) {
" = " + default
}
… but you need:
default = "false"
if (default) {
" = " + default
}
So this would do it for you:
object = [{
name: 'A',
fields: { type: "string" }
},
{
name: 'B',
fields: { type: "boolean", default: "false" }
}]
… and change the {{^default}} block to {{#default}}:
{{#object}}
var {{name}}: {{#fields}} {{type}} {{#default}} = {{default}} {{/default}}{{/fields}}
{{/object}}
this work for me:
object : [
{
name: 'A',
fields: { type: "string" }
},
{
name: 'B',
fields: { type: "boolean", default: "false"}
}
]
with
{{#object}}
var {{name}}: {{#fields}} {{type}} {{#default}} = {{default}} {{/default}}{{^default}}{{/default}}{{/fields}}
{{/object}}
if the false cannot change to "false" and you want a result like you show above,you may try:
object : [
{
name: 'A',
fields: { type: "string", default: true}
},
{
name: 'B',
fields: { type: "boolean", default: false}
}
]
with
{{#object}}
var {{name}}: {{#fields}} {{type}} {{#default}}{{/default}}{{^default}}= false{{/default}}{{/fields}}
{{/object}}

Not getting record on itemtap sencha list

When Taping items the listener is getting invoked but the value is null. My Code:
Ext.define('tablet.SelectCategories', {
extend: 'Ext.navigation.View',
xtype: 'selectcategorypanel',
id: 'SelectCategories',
requires:[
],
initialize:function(){
this.callParent();
var jsonObject = Ext.create('Tablet')
.make_webservice_call_post('get_categories');
Ext.getCmp('select_category_list')
.setData(jsonObject.info);
console.log(jsonObject.info);
},
config: {
//title : 'Select Categories',
//iconCls: 'team',
//styleHtmlContent: true,
// scrollable: true,
layout: {
type: 'card'
},
items: [
{
fullscreen: true,
mode: 'MULTI',
xtype: 'list',
itemTpl: '{name}',
autoLoad: true,
id:'select_category_list',
store: {
fields: ['active','created','description','name']
},
listeners: {
itemtap: function (list, records) {
console.log('Sel');
console.log(records.name);
var names = [];
Ext.Array.each(records, function (item) {
names.push('<li>' + item.data.name + '</li>');
}); // each()
Ext.Msg.alert('You selected ' + records.length + ' item(s)',
'<ul>' + names.join('') + '</ul>');
} // selectionchange
}
// handler:self.itemClick
}
Getting undefined in console.log(records.name);
Your method signature for itemtap is also wrong. It should be -
itemtap: function(list, index, target, record) {
console.log('Item tapped');
console.log(record.get('name'));
// and your rest of the code.
}
Check the documentation for the itemtap event here, and read up more about stores here.

Unable to add radio buttons to Kendo UI grid

I'm trying to have a group of 3 radio buttons (each button in different column but the same row) in my Kendo grid but without success. I looked at the Kendo RowTemplate doc, but it's not directing me to any solution.
it works fine with checkboxes, but when i change the template to "radio" type, it changes to checkbox the second I click the edit button. any thoughts?
below is my kendoGrid properties, I put ** next to the 'template' line in the field property.
div.kendoGrid({
dataSource:
{ error: function (e) {
alert("An error occured: "+ e.xhr.responseText);
this.cancelChanges();
},
type:"json",
transport: {
read: {
url: "/users/read",
cache: false,
dataType: "json"
},
update: {
url: function(user){
var grid = $("#grid").data("kendoGrid");
var model = grid.dataItem(grid.select());
var roleIs;
if (user.Admin) {
roleIs="admin"
}
else if (user.Manager) {
roleIs="manager"
}
else if (user.User) {
roleIs="user"
};
return "users/update/"+model.id+"/"+roleIs+"/"+user.name
},
type: "PUT"
},
destroy: {
url: function(user){
return "/users/destroy/"+user.id+"/"+user.name
},
type: "DELETE"
},
create: {
url: function(user){
var roleIs;
if (user.Admin) {
roleIs="admin"
}
else if (user.Manager) {
roleIs="manager"
}
else if (user.User) {
roleIs="user"
};
return "users/create/"+user.login+"/"+user.name+"/"+roleIs+"/"
},
type: "POST"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
schema: {
model:
{ id: "id",
fields: {
id:{ type: "number",editable: false},
role:{ type: "string"},
login: { type: "string",editable: false},
name:{type: "string",editable: false},
Admin: { type: "boolean"},
Manager: { type: "boolean"},
User: { type: "boolean"}
}
}
},
pageSize: 30,
serverPaging: false,
serverFiltering: false,
serverSorting: false
},
selectable: "row",
navigatable: true,
pageable: true,
height: 400,
columns: [//{field: "id"},
{
field: "name",
title:"User Name",
filterable: true,
nullable: false,
editable: false
},{
field: "Admin",
**template: '<input type="checkbox" #= Admin ? "checked=checked" : "" # disabled="disabled"></input>'**,
width: 75
},{
field: "Manager",
**template: '<input type="checkbox" #= Manager ? "checked=checked" : "" # disabled="disabled"></input>'**,
width: 75
},{
field: "User",
**template: '<input type="checkbox" #= User ? "checked=checked" : "" # disabled="disabled"></input>',**
width: 75
},{
command: ["edit", "destroy"], title: "", width: "195px"
}],
editable:{mode: "inline"}
});
}
}
}
The formatting for edition is controlled by columns.editor
You need to write an editor function that defines the input as a radio button.

Sencha touch - trying to delete row from list

I try to get an editable list with this code:
var isEditing = false;
new Ext.Application({
launch: function(){
new Ext.Panel({
//layout: 'card',
fullscreen: true,
items: new Ext.List({
id: 'myList',
store: new Ext.data.Store({
fields: ['myName'],
data: [{ myName: 1 }, { myName: 2 }, { myName: 3}]
}),
itemSelector: '.x-list-item',
multiSelect: true,
itemTpl: '<span class="name">{myName}</span>',
tpl: new Ext.XTemplate(
'<tpl for=".">' +
'<div class="x-list-item">' +
'<tpl if="this.isEditing()">' +
'<img src="images/delete.gif" ' +
'onclick="Ext.getCmp(\'myList\').myDeleteItem({[xindex-1]})" ' +
'style="vertical-align: middle; margin-right: 15px;"/>' +
'</tpl>' +
'{myName}</div>' +
'</tpl>',
{
compiled: true,
isEditing: function () {
console.log('isEditing (tpl):' + isEditing)
return isEditing;
}
}),
myDeleteItem: function (index) {
var store = this.getStore();
var record = store.getAt(index);
console.log('removing ' + record.data.myName);
store.remove(record);
},
listeners: {
itemtap: function () {
if (isEditing){
console.log('isEditing: ' + isEditing);
return;
}
},
beforeselect: function () {
console.log('isEditing: before ' + !isEditing);
return !isEditing;
}
}
}),
dockedItems: [{
dock: 'top',
xtype: 'toolbar',
layout: { pack: 'right' },
items: [
{
xtype: 'button',
text: 'Edit',
handler: function () {
var list = Ext.getCmp('myList');
if (!isEditing)
list.mySelectedRecords = list.getSelectedRecords();
isEditing = !isEditing;
this.setText(isEditing ? 'Save' : 'Edit');
list.refresh();
if (!isEditing)
list.getSelectionModel().select(list.mySelectedRecords);
}
}]
}]
});
}
});
but its not working like it should. If I press the EDIT button there is no delete-image and so there is no deleted item....
There are 3 things that I can see:
The Template is rendered once, you will need to call .refresh() or .refreshNode() on the list to update any item templates. The better way to accomplish this would be to hide the delete button via CSS and display it when the 'edit' button is clicked.
There is probably a naming conflict between the isEditing variable declared at the top and the isEditing function reference. It is very confusing to have these two things named the same, and can lead to problems with variable scoping.
The click event that you are looking for may be intercepted by the parent list item and Sencha Touch is turning it into a 'itemtap' event on the list item.
I was not able to delete until I added an id field without a datatype to my model. I don't know why as it should know which record to delete via the index.
Ext.regModel('Setting', {
fields: [
{name: 'id'}, // delete works after adding
{name: 'name', type: 'string'}
],
proxy: {
type: 'localstorage',
id: 'settings'
}
Kevin