why is the code crashing when using jeditable? - jeditable

The code crashes when html tags are entered as input when making fields editable by using jeditable.
It opens my custom error page in the text area itself with the error message "A potentially dangerous Request.Form value was detected from the client "
When user tries to normally save new information the call goes to EditData method at Controller but when user enters html tag and tries to save the code crashes and call does not go to EditData at Controller
$('.editArea').editable('../Data/EditData', {
cssclass: 'jeditForm',
tooltip: 'click to edit',
width: '100%',
height: '150',
type: 'textarea',
title: '',
placeholder: 'click to edit',
submit: 'save',
onsubmit: function (settings, original) {
oldValue = original.revert;
},
submitdata: function (value) {
return {
id: $(this).data('id'),
propertyName: $(this).data('propertyname')
}
},
callback: function (value, settings) {
var jsonData = $.parseJSON(value);
if (jsonData.status) {
this.innerText = jsonData.value;
}
else {
alert("not updated");
this.innerText = oldValue;// + "\n" + jsonData.msg;
}
}
});

Related

TypeScript FormIO Custom Component doesnt Render & cant add Even Listeners

I have created a custom component in FormIO. I have followed the tutorial on the Check Matrix component and I am having issues trying to:
get the type to render as a custom name "e.g. mycomp". It returns "unknown component: mycomp" in the builder. I reverted to using a type that is known by FormIO like "textfield" and it renders
Adding eventlisteners to my component is not triggering
How can I get the component to render and add my events to this component? What i am doing wrong?
InputComponent.ts
Import { Components } from "formiojs";
const Field = Components.components.field;
export default class loqateAddressComponent extends (Field as any) {
constructor(component, options, data) {
super(component, options, data);
}
static schema(...extend:any[]) {
return Field.schema({
type: 'textfield', //want this to be customname but it wont render
label: 'Xrm Address',
key: 'loqateaddress',
...extend});
}
static get builderInfo() {
return {
title: 'Loqate Address',
group: 'basic',
icon: 'home',
documentation: '/userguide/#address',
weight: 35,
schema: loqateAddressComponent.schema(),
};
}
renderInput(){
return this.renderTemplate('input', {
input: {
type: 'input',
ref: `${this.component.key}`,
attr: {
id: `${this.component.key}`,
class: 'form-control',
type: 'search',
}
}
});
}
public render(children) {
return super.render(this.renderTemplate('loqateaddress',{
renderInputType: this.render.bind(this)
}));
}
public attach(element: any) {
const refs = {};
refs[`${this.component.key}`] = "input";
this.loadRefs(element, refs);
console.log("attach rendered");
this.addEventListener(element, 'change', ()=> {
console.log("address clicked");
});
return super.attach(element);
}
}
Form.ejs (For my template)
<div>
{% {{ctx.renderInputType}} %}
</div>

Code migration from tinymce 4 to tinymce 5 - problem with action function (true / false)

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!

How do I access the values in the JSON model in my Dialogue list?

I have retrieved a JSON model from an ajax call in UI5 but I can't access its members. I have seen examples of people doing something similar but it isn't working for me. Here is my code:
onSumbmitFlowGAkQ: function () {
var oParameters = {
"value": this.getView().byId("flowInputGAK").getValue()
};
$.ajax({
url: "private url",
type: 'POST',
data: JSON.stringify(oParameters),
contentType: 'application/json',
success: function (data) {
this.getView().setModel(new JSONModel(data), "guidedAssistanceGAK");
this.setUpDialog();
}.bind(this),
error: function (e) {
MessageToast.show(e.status);
}
});
setUpDialog: function () {
var lst = new List({
items: {
path: "guidedAssistanceGAK>/flow",
template: new StandardListItem({
title: "{guidedAssistanceGAK>value}",
counter: "{guidedAssistanceGAK>ID}"
})
}
});
var dialog = new Dialog({
title: "choose one",
content: lst,
beginButton: new Button({
text: "OK",
press: function () {
dialog.close();
}
}),
afterClose: function () {
dialog.destroy();
}
});
dialog.open();
//this.oEditor.oRichTextEditor.setValue(this.getView().getModel("guidedAssistanceGAK").getProperty("/flow"));
},
I am using the syntax "guidedAssistanceGAK>/flow" to access the data but it isn't working. I think this is a binding error. I was wondering what would be the right way to do this.
The new dialog doesn't look to be part of the view, which is where your model lives. You could either do this.getView().addDependent(dialog), or you could attach the model to the dialog with dialog.setModel.

is it possible to change button's text with $ionicPopup.confirm()?

I'm using $ionicPopup.confirm() but I would like to change "cancel's button" text. Is it possible to do so ?
I'm aware of .show() syntax:
buttons: [
{ text: 'Cancel' }
]
But it does not seem to work with .confirm() ...
Thank 4 the help
At least in the latest release of Ionic (1.0.0) you can do the following:
var confirmPopup = $ionicPopup.confirm({
title: 'Popup title',
template: 'Popup text',
cancelText: 'Custom cancel',
okText: 'Custom ok'
}).then(function(res) {
if (res) {
console.log('confirmed');
}
});
Here is the relative documentation.
UPDATE : on ionic 1.0.0, this is now possible, check here
showConfirm Options :
{
title: '', // String. The title of the popup.
cssClass: '', // String, The custom CSS class name
subTitle: '', // String (optional). The sub-title of the popup.
template: '', // String (optional). The html template to place in the popup body.
templateUrl: '', // String (optional). The URL of an html template to place in the popup body.
cancelText: '', // String (default: 'Cancel'). The text of the Cancel button.
cancelType: '', // String (default: 'button-default'). The type of the Cancel button.
okText: '', // String (default: 'OK'). The text of the OK button.
okType: '', // String (default: 'button-positive'). The type of the OK button.
}
Yes you can do wathever you want, using ionic popup.show and bind the Cancel event.
$ionicPopup.show({
template: msg,
title: titleConfirm,
buttons: [
{ text: "BTN_NO",
onTap:function(e){
return false;
}
},
{ text: "BTN_OK",
onTap:function(e){
return true;
}
},
]
});
After investigation on the ionic popover.confirm function this is
not possible to customize it. The value of popover.confirm are hardcoded line 446
function showConfirm(opts) {
return showPopup(extend({
buttons: [{
text: opts.cancelText || 'Cancel',
type: opts.cancelType || 'button-default',
onTap: function() { return false; }
}, {
text: opts.okText || 'OK',
type: opts.okType || 'button-positive',
onTap: function() { return true; }
}]
}, opts || {}));
}
It's possible to do, you have to use the "type" thing inside the button
buttons: [
{ text: 'Cancel' },
{
text: '<b>Save</b>',
type: 'button-assertive',
onTap: function(e) {
$scope.request_form.abc = "accepted";
}
}
]
in the type part you have to give the class name , and you can change the color of the button.

Extjs 4.0 MVC Add components to a form based on Store

I am ashamed to say I have spent most of today on this. I am trying to build a form based on the contents of an data store. I am using Ext.js and the MVC architecture. Here's what I have:
var myitems = Ext.create('Ext.data.Store', {
fields: ['name', 'prompt', 'type'],
data :
[
{"name":"name", "prompt":"Your name" , "type":"textfield"},
{"name":"addr", "prompt":"Your street address", "type":"textfield"},
{"name":"city", "prompt":"Your city" , "type":"textfield"}
]
});
function genwidget(name, prompt, type)
{
console.log("In genwidget with name=" + name + ", prompt=" + prompt + ", type=" + type + ".");
var widget = null;
if (type == "textfield")
{
// widget = Ext.create('Ext.form.field.Text',
widget = Ext.create('Ext.form.TextField',
{
xtype : 'textfield',
name : name,
fieldLabel: prompt,
labelWidth: 150,
width : 400, // includes labelWidth
allowBlank: false
});
}
else
{
// will code others later
console.log("Unrecongized type [" + type + '] in function mywidget');
}
return widget;
};
function genItems(myitems)
{
console.log("Begin genItems.");
var items = new Ext.util.MixedCollection();
var howMany = myitems.count();
console.log("There are " + howMany + " items.");
for (var i = 0; i < myitems.count(); i++)
{
var name = myitems.getAt(i).get('name');
var prompt = myitems.getAt(i).get('prompt');
var type = myitems.getAt(i).get('type');
var widget = genwidget(name, prompt, type) ;
items.add(widget);
console.log("items.toString(): " + items.toString());
}
return items;
};
Ext.define('MyApp.view.dynamicform.Form' ,{
extend: 'Ext.form.Panel',
alias : 'widget.dynamicformform',
// no store
title: 'Dynamic Form',
id: 'dynamicform.Form',
bodyPadding: 5,
autoScroll: true,
layout: 'auto',
defaults:
{
anchor: '100%'
},
dockedItems: [ ],
items: genItems(myitems),
// Reset and Submit buttons
buttons: [
{
text: 'Reset',
handler: function()
{
this.up('form').getForm().reset();
console.log('Reset not coded yet');
}
},
{
text: 'Submit',
formBind: true, //only enabled once the form is valid
disabled: true,
handler: function()
{
var form = this.up('form').getForm();
if (form.isValid())
{
form.submit({
success: function(form, action)
{
console.log('Success not coded yet');
}
});
}
}
} // end submit
], // end buttons
initComponent: function()
{
console.log("--> in dynamicform init");
this.callParent(arguments);
console.log("--> leaving dynamicform init");
}
}); // Ext.define
The error I am getting (I've had many throughout the day) is "my.items.push is not a function".
Thanks in advance for any help you can offer!
items is expected to be an array not MixedCollection. It is changed to MixedCollection later on if I remember good. So to fix your issue change:
var items = new Ext.util.MixedCollection();
// ...
items.add(widget);
to
var items = [];
// ...
items.push(widget);
Consider as well defining items of form as an empty array and then in initComponent make use of Ext.apply:
var me = this,
items = genItems(myitems);
Ext.apply(me, {
items:items
});