Abbiamo un plug-in di file/immagine/gestione documenti sviluppato internamente per TinyMCE che viene ancora trasferito su jQuery. Nel frattempo, alcuni dei nostri progetti che si basano sull'avere queste funzionalità devono utilizzare la versione basata su Prototype di TinyMCE & jQuery.noConflict(). Funziona bene tuttavia con la convalida non invadente in ASP.NET MVC 3 la convalida su submit avviene prima che il callback TinyMCE per copiare i contenuti di TinyMCE sul campo modulo sia attivato. È possibile agganciare un evento di pre-convalida nella convalida non invadente?ASP.NET MVC 3 convalida discreta, invio e TinyMCE
risposta
Se si utilizza bottoni di invio di inviare il modulo, provate questo:
$("input[type='submit']").click(function() {
tinyMCE.triggerSave();
});
Se non stai utilizzando i pulsanti di invio, basta agganciare in qualunque evento si verifica immediatamente prima scheda di iscrizione e chiamare tinyMCE.triggerSave ().
Un altro modo per ottenere questo controllo maggiore è l'inizializzazione di TinyMCE. Funziona bene tranne per un caso: l'ultima istanza TinyMCE che si esce non attiva l'evento onDeactivate in TinyMCE (è solo trigger quando si passa a un'altra istanza di TinyMCE). Quindi ecco un modo per ovviare a questo - finora sembra funzionare bene ma YMMV.
Nota: lo utilizzerei insieme alla risposta accettata. Questo codice attiva la convalida mentre il contenuto viene modificato in TinyMCE.
tinyMCE.init({
...
setup: ValidationTinyMceSetup
});
E il nostro metodo di configurazione:
function ValidationTinyMceSetup(editor) {
var $textarea = $('#' + editor.editorId);
// method to use to save editor contents to backend input field (TinyMCE hides real input and syncs it up
// with values on form submit) -- we need to sync up the hidden input fields and call the valid()
// method from jQuery unobtrusive validation if it is present
function save(editor) {
if (editor.isDirty) {
editor.save();
var $input = $('#' + editor.editorId);
if (typeof $input.valid === 'function')
$input.valid();
}
}
// Save tinyMCE contents to input field on key/up down (efficiently so IE-old friendly)
var typingTimerDown, typingTimerUp;
var triggerDownSaveInterval = 1000; // time in ms
var triggerUpSaveInterval = 500; // time in ms
editor.onKeyDown.add(function (editor) {
clearTimeout(typingTimerDown);
typingTimerDown = setTimeout(function() { save(editor) }, triggerDownSaveInterval);
});
editor.onKeyUp.add(function() {
clearTimeout(typingTimerUp);
typingTimerUp = setTimeout(function() { save(editor) }, triggerUpSaveInterval);
});
// Save tinyMCE contents to input field on deactivate (when focus leaves editor)
// this is via TAB
editor.onKeyDown.add(function (editor, event) {
if (event.keyCode === 9)
save(editor);
});
// this is when focus goes from one editor to another (however the last one never
// triggers -- need to enter another TinyMCE for event to trigger!)
editor.onDeactivate.add(function (editor) {
save(editor);
});
}
Infine, un elemento di bonus che è completamente estraneo: è possibile aggiungere un contatore di caratteri includendo questa funzione nel vostro sorgente JavaScript:
function CharacterCountDisplay(current, max) {
if (current <= max) {
return current + ' of ' + max + ' characters max';
}
else {
return '<span style="color: red;">' + current + '</span> of ' + max + ' characters';
}
}
E nel metodo ValidationTinyMceSetup
precedente aggiungere:
// check for character count data-val
var character_max = $textarea.attr('data-val-lengthignoretags-max');
if (typeof character_max === 'undefined' || character_max === false) {
character_max = $textarea.attr('data-val-length-max');
}
if (typeof character_max !== 'undefined' && character_max !== false) {
var character_count = function (editor) {
var currentLength = $(editor.getDoc().body).text().length;
editor.dom.setHTML(tinymce.DOM.get(editor.id + '_path_row'), CharacterCountDisplay(currentLength, character_max));
};
// on load show character count
editor.onInit.add(character_count);
// while typing update character count
editor.onKeyUp.add(character_count);
}
Per utilizzare semplicemente aggiungere uno data-val-length-max="250"
al tag textarea o qualsiasi altra cosa si sta utilizzando TinyMCE!
- 1. RequiredAttribute con AllowEmptyString = true in ASP.NET MVC 3 convalida discreta
- 2. ASP .Net MVC 3: convalida discreta personalizzata
- 3. Che cos'è jQuery Convalida discreta?
- 4. ASP.net MVC convalida Hook
- 5. Convalida personalizzata/condizionale discreta con Fluent Validation
- 6. ASP.NET MVC 3 Convalida remota per consentire il valore originale
- 7. Asp.net MVC 3 Validazione esclude qualche convalida campo in TryUpdateModel
- 8. Convalida modulo TinyMCE e HTML5
- 9. Perché ASP.NET MVC 3 non convalida correttamente i miei float?
- 10. ASP.Net MVC 3 Modello JSON Convalida del modello lato server e binding con convalida lato client
- 11. ASP.NET MVC 3 Autenticazione utente
- 12. Differenza tra ASP.NET MVC 3 e 4?
- 13. ASP.NET MVC 3 e NHibernate Scaffolding
- 14. ASP.NET MVC 3 Custom RouteBase e OutputCache
- 15. ASP.NET MVC 3 e cartella App_Code
- 16. asp.net convalida lato client mvc
- 17. ASP.NET MVC 4 Cap convalida
- 18. ASP.NET MVC 5 Convalida modulo
- 19. Confronta date DataAnnotations convalida asp.net mvc
- 20. ASP.Net MVC 3 Azione controller e Apri nuova finestra
- 21. ASP.NET MVC 3 Generic DisplayTemplates
- 22. ASP.NET MVC 3 Viewmodel Pattern
- 23. ASP.NET MVC 3 _Layout.cshtml Controller
- 24. ASP.NET MVC 3 Esercitazioni indispensabili
- 25. ASP.NET MVC 3 Razor Performance
- 26. ASP.NET MVC 3 HiddenFor Javascript
- 27. ASP.NET MVC 3 utilizzando l'autenticazione
- 28. ASP.NET MVC 3 Landing Page
- 29. Impossibile installare Asp.net MVC 3
- 30. asp.net MVC Web API VS asp.net MVC 4 e applicazione Internet MVC 3
Questo funziona! Ci stavo pensando e mi sono preoccupato per alcune persone che sostenevano bug con 'triggerSave()'. L'ho fatto in questo modo: in 'tinyMCE.init ({oninit: mySpecialSubmit, ...});' e 'mySpecialSubmit' ha la chiamata' triggerSave() '. Funziona alla grande! Grazie! – Cymen
Non dimenticare di inserirlo all'interno di '$ (document) .ready (function() {})'. –