I am working on a project where I using tinymce with the codesample plugin.
When I am set up some code in the codesample every thing is fine but after I saved this code in the database and goes to the view page every thing is in one row. It looks like that all the breaks are removed.
I'm doing this project in Asp.net core mvc entity framework.
<script>
tinymce.init({
selector: '#ArtikelInhoud',
plugins: "code",
plugins: 'codesample',
codesample_languages: [
{ text: 'HTML/XML', value: 'markup' },
{ text: 'JavaScript', value: 'javascript' },
{ text: 'CSS', value: 'css' },
{ text: 'PHP', value: 'php' },
{ text: 'Ruby', value: 'ruby' },
{ text: 'Python', value: 'python' },
{ text: 'Java', value: 'java' },
{ text: 'C', value: 'c' },
{ text: 'C#', value: 'csharp' },
{ text: 'C++', value: 'cpp' }
],
remove_linebreaks: false,
convert_newlines_to_br: true,
force_br_newlines: true
});
</script>
When you render content created with the codesample plugin you need to include some code from Prism when you do so. This is documented on the codesample plugin page:
https://www.tiny.cloud/docs/plugins/codesample/#usingprismjsonyourwebpage
You need to add prism.js and prism.css to your page in order to get
the syntax highlighted code samples on your webpage (as created by the
Code Sample plugin). The Code Sample plugin uses the following
languages: markup, javascript, css, php, ruby, python, java, c, csharp
and cpp. You can generate the prism.js and prism.css files on the
download page at the Prism website.
I did not successfully reproduce your problem, the following is a successful example, you can refer to it.
(I hope you can provide the complete code, tell us how you submitted the data, and the corresponding js and css references.)
Data class:
public class Data
{
public string Content{ get; set; }
}
controller:
public IActionResult Test()
{
return View();
}
[HttpPost]
public IActionResult Test(Data data)
{
//save the content in data.Content to database
return View(data);
}
View:
#model WebApplication_core_mvc.Models.Data
#{
ViewData["Title"] = "Test";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>Test</h1>
#section Scripts{
<script src="https://cloud.tinymce.com/stable/tinymce.min.js?apiKey=qagffr3pkuv17a8on1afax661irst1hbr4e6tbv888sz91jc" referrerpolicy="origin"></script>
<script>
tinymce.init({
selector: '#ArtikelInhoud',
plugins: "code",
plugins: 'codesample',
codesample_languages: [
{ text: 'HTML/XML', value: 'markup' },
{ text: 'JavaScript', value: 'javascript' },
{ text: 'CSS', value: 'css' },
{ text: 'PHP', value: 'php' },
{ text: 'Ruby', value: 'ruby' },
{ text: 'Python', value: 'python' },
{ text: 'Java', value: 'java' },
{ text: 'C', value: 'c' },
{ text: 'C#', value: 'csharp' },
{ text: 'C++', value: 'cpp' }
],
remove_linebreaks: false,
convert_newlines_to_br: true,
force_br_newlines: true
});
</script>
}
<form asp-action="Test" method="post">
<textarea id="ArtikelInhoud" asp-for="Content">
</textarea>
<input id="Button1" type="submit" value="button" class="btn btn-primary" />
</form>
Here is the result:
Related
i am building a chatting mobile app with ionic 5, i want to be able to scroll to the bottom of the chat but its not working, i searched online but the solution i saw wasn't working, it just scrolled a little bit, but not to the end of the chat
Here is my code for the chat.page.html
<ion-header>
....
</ion-header>
<ion-content class="bg">
<ion-button expand="block" (click)="scrollContent()">Scroll 1</ion-button>
<div class="chat-container">
<div *ngFor="let message of messages; let i=index;" class="chat-bubble" [(ngClass)]="message.type">
<h6>{{ message.text }}</h6>
<p>{{ message.created }}</p>
</div>
</div>
</ion-content>
<ion-footer>
.......
</ion-footer>
Here's the code for the chat.page.ts
import { Component, OnInit, ViewChild } from '#angular/core';
import { IonContent } from '#ionic/angular';
#Component({
selector: 'app-chats',
templateUrl: './chats.page.html',
styleUrls: ['./chats.page.scss'],
})
export class ChatsPage implements OnInit {
messages=new Array()
#ViewChild(IonContent, { static: false }) content: IonContent;
constructor(
) { }
ngOnInit() {
this.messages=[
{ text: "Hey what's up?", type: 'received', created: '14:02' },
{ text: "Nothing", type: 'send', created: '14:05' },
{ text: "Want to go to the movies?", type: 'send', created: '14:05' },
{ text: "I'm sorry, I can't", type: 'received', created: '14:15' },
{ text: "but can we go tomorrow?", type: 'received', created: '14:16' },
{ text: "Nothing", type: 'send', created: '14:05' },
{ text: "Nothing", type: 'send', created: '14:05' },
{ text: "Nothing", type: 'send', created: '14:05' },
{ text: "Nothing", type: 'send', created: '14:05' },
{ text: "I'm sorry, I can't", type: 'received', created: '14:15' },
{ text: "but can we go tomorrow?", type: 'received', created: '14:16' },
]
}
scrollContent() {
this.content.scrollToBottom(300)
}
}
I want it to scroll to the bottom of the div with class="chat-container" when i click the button.
Please what am i doing thats not right
try this
scrollToBottomSetTimeOut(){
setTimeout(() => {
this.content.scrollToBottom();
}, 30);
}
Following example is add a custom dropdown to tinyMCE, is it possible to change again after init tinyMCE? for example, after init the tinyMCE, update the list again by another button by different list.
https://codepen.io/tinymce/pen/JYwJVr
tinymce.init({
selector: 'textarea',
height: 500,
toolbar: 'mybutton',
menubar: false,
content_css: [
'//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
'//www.tinymce.com/css/codepen.min.css'],
setup: function (editor) {
editor.addButton('mybutton', {
type: 'listbox',
text: 'My listbox',
icon: false,
onselect: function (e) {
editor.insertContent(this.value());
},
values: [
{ text: 'Menu item 1', value: ' <strong>Some bold text!</strong>' },
{ text: 'Menu item 2', value: ' <em>Some italic text!</em>' },
{ text: 'Menu item 3', value: ' Some plain text ...' }
],
onPostRender: function () {
// Select the second item by default
this.value(' <em>Some italic text!</em>');
}
});
}
});
I didn't find any choice that I can update only for the custom dropdown. This is not what good way but the only way I can make it work. So what I did was remove tinymce and re-add it again.
tinymce.remove();
tinymce.init({
selector: 'textarea',
setup: function (editor) {
var self = this;
editor.addButton('mybutton', {
type: 'listbox',
text: 'myList',
icon: false,
onselect: function (e) {
editor.insertContent(this.value());
},
values: newList,
onPostRender: function () {
// Select the second item by default
this.value(' <em>Some italic text!</em>');
}
});
}
});
Iam using DevExtreme 14.2 version, am not able to set default value on dxRadioGroup. consider the following code i don't know where i did mistake.
HTML:
<div data-bind="dxRadioGroup: { dataSource: items, layout: 'horizontal', value: defaultvalue, valueExpr: 'this' }"></div>
JS:
dxSample_13_2.home = function (params) {
var viewModel = {
items: [
{ text: "Tea" },
{ text: "Coffee" },
{ text: "juice" }
],
defaultvalue: ko.observable(items[2]),
}
return viewModel;
};
Looks like you have an error in your code. There is no items variable that you try to access.
var items = [
{ text: "Tea" },
{ text: "Coffee" },
{ text: "juice" }
];
var viewModel = {
items: items,
defaultvalue: ko.observable(items[2])
};
See working fiddle: http://jsfiddle.net/tabalinas/tfvtq9y0/
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();
I am new to ExtJS 4 and am trying to implement a simple application in MVC style. The documentation is really good and this is one of the topics covered in the Form package guide, but it doesn't seem to work in my case.
The app basically can create, edit and delete articles.The creation and editing are in pop-up windows.
The pop-up window contains a form with a text field and html-editor.
Please click on the link below,this is the error in Google Chrome Console when I click on the submit button in the 'window'
http://www.freeimagehosting.net/mjig7
Here is the code which I've written
Model:
Ext.define('AM.model.Article', {
extend: 'Ext.data.Model',
fields: ['name', 'data'],
proxy: {
type: 'rest',
url: 'users/data',
reader: {
type: 'json',
root: 'myJaxBean',
successProperty: 'success'
},
writer: {
type: 'json'
}
}
});
View:
Ext.define('AM.view.New', {
extend: 'Ext.window.Window',
alias : 'widget.new',
title : 'New Article',
autoShow: true,
fieldDefaults: {
labelAlign: 'top',
msgTarget: 'side'
},
layout: 'fit',
bodyStyle:'padding:5px 5px 0',
width: '70%',
height: '40%',
initComponent: function() {
this.items = [
{
xtype: 'form',
anchor: '99%',
items: [
{
xtype: 'textfield',
name : 'name',
fieldLabel: 'Article Name',
anchor: '99%'
},
{
xtype: 'htmleditor',
name : 'data',
fieldLabel: 'Article',
anchor: '99% -25'
}
],
buttons: [
{
text: 'Submit',
handler: function() {
var form = this.up('form').getForm(), // get the basic form
record = form.getRecord(); // get the underlying model instance
if (form.isValid()) { // make sure the form contains valid data before submitting
form.updateRecord(record); // update the record with the form data
record.save({ // save the record to the server
success: function(user) {
Ext.Msg.alert('Success', 'User saved successfully.')
},
failure: function(user) {
Ext.Msg.alert('Failure', 'Failed to save user.')
}
});
} else { // display error alert if the data is invalid
Ext.Msg.alert('Invalid Data', 'Please correct form errors.')
}
}
},
{
text: 'Cancel',
scope: this,
handler: this.close
}
]
}
],
this.callParent(arguments);
}
});
and finally the code in my controller which makes the window visible
Controller:
.....
'viewport > panel > panel > tbar button[action=newarticle]' :{
click: this.newArticle
},
....
newArticle: function(button){
var view = Ext.widget('new');
},
Please point me in the right direction in case I am doing something wrong.
Thanks in advance.
Check the docs getRecord():
Returns the last Ext.data.Model instance that was loaded via
loadRecord
so it's clear that you haven't load any record, so you getRecord() returns undefined. And you are getting your error further.