Apr 02

JQuery: Visualizzazione Form in sola lettura

Tag: Senza categoriafenix @ 15:28

Snippet javascript per visualizzare un Form in sola lettura.

Utilizzo:

jQuery('#ID_OGGETTO').toViewMode('view');

Per il corretto funzionamento é richiesto il framework jQuery.

jQuery.fn.extend({
	toView: function() {
		if (this.is(':visible') && !this.is('textarea')) {
			var defaultEmptyValue = "";
			for ( i = 0; i < this.parent(":first").width()/9; i++) {
				defaultEmptyValue += " ";
			}
			if (this.is('input')) {
				this.attr("readonly", true);
				if (this.attr('type') == 'button' || this.attr('type') == 'type' || this.attr('type') == 'reset') {
					if (this.hasClass('arca-op-hide')) {
						this.remove();
					}
				} else if (this.attr('type') == 'checkbox') {
					if (this.is(':checked')) {
						this.replaceWith("");
					} else {
						this.replaceWith("");
					}
				} else if (this.attr('type') == 'radio') {
					if (this.is(':checked')) {
						this.replaceWith("");
					} else {
						var elemId = this.attr("id") || "";
						this.next("label[for=" + elemId + "]").remove();
						this.prev("label[for=" + elemId + "]").remove();

						this.remove();
					}
				} else {
					var value = this.val();
					if (ArcaUtils.isEmpty(value)) {
						value = defaultEmptyValue;
					}
					this.replaceWith("" + value + "");
				}
			} else if (this.is('select')) {
				this.attr("readonly", true);
				if (ArcaUtils.isEmpty(this.find(':selected').val())) {
					this.replaceWith("" + defaultEmptyValue + "");
				} else {
					this.replaceWith("" + this.find(':selected').text() + "");
				}
			}
	    } else if (this.is('textarea')) {
			this.attr("readonly", true);
			var text = this.text() || this.val();

			var elemId = this.attr('id') || '';

			this.replaceWith("\
			 		\
\
\
\


\
			 				

\
			 			

\
			 			
\ \ \
" + ((ArcaUtils.isNotEmpty(text)) ? text : "") + "
\
\
"); var elemId = this.attr('id') || ''; if (typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById(elemId) != null && tinyMCE.getInstanceById(elemId) != 'undefined') { tinyMCE.execCommand('mceFocus', false, elemId); tinyMCE.execCommand('mceRemoveControl', false, elemId); } } }, toViewMode: function(mode) { mode = mode || ''; var obj = this; var workToDo = function () { if (mode == 'view') { if (obj.is("form")) { obj.attr("action", "#"); obj.submit(function() {return false;}); } jQuery.each(obj.find('input'), function(i, value) { jQuery(value).toView(); }); jQuery.each(obj.find('textarea'), function(i, value) { jQuery(value).toView(); }); jQuery.each(obj.find('select'), function(i, value) { jQuery(value).toView(); }); jQuery.each(obj.find('.arca-op-hide'), function(i, value) { jQuery(value).empty(); }); jQuery.each(obj.find('.arca-value'), function(i, value) { if (ArcaUtils.isEmpty(jQuery(value).text())) { var defaultEmptyValue = ""; for ( i = 0; i < jQuery(value).parent(":first").width()/9; i++) { defaultEmptyValue += " "; } jQuery(value).html(defaultEmptyValue); } }); obj.remove(":contains('*')"); } }; setTimeout(workToDo, 0); } });

4 Responses to “JQuery: Visualizzazione Form in sola lettura”

  1. Vincent says:

    GRANDE PORTUS !

  2. Public Tube says:

    Do you use any cache addon on this site?

  3. html5 developers says:

    My partner and i like, bring about I stumbled upon just the thing I was in search of. You may have finished our four evening lengthy hunt! Our god Bless you gentleman. Have got a awesome time. Ok bye

  4. Johna63 says:

    Howdy would you mind sharing which blog platform you’re working fdcggfeekaae

Leave a Reply



Hello !