Pregunta sobre Contact Form 7 de Wordpress:

$ (…) No aplica .wpcf7InitForm ()

Un usuario preguntó 👇

Hola,

con la última versión y caída de jquery.forms, la función wpcf7InitForm() Ya no está disponible. Estaba usando esta función para mi sitio impulsado por ajax para reiniciar CF7 para nuevos formularios en todas las cargas de páginas de ajax. ¿Existe otra (nueva) forma de iniciar CF7 sobre la marcha?

Rasso es mejor

(@nonverbla)

Hace 3 años, 7 meses

entonces … una posible solución es devolver la primera función de autoaspiración completa a la función wpcf7.init ():


wpcf7.init = function() {

	$( function() {
		wpcf7.supportHtml5 = ( function() {
			var features = {};
			var input = document.createElement( 'input' );

			features.placeholder = 'placeholder' in input;

			var inputTypes = [ 'email', 'url', 'tel', 'number', 'range', 'date' ];

			$.each( inputTypes, function( index, value ) {
				input.setAttribute( 'type', value );
				features[ value ] = input.type !== 'text';
			} );

			return features;
		} )();

		$( 'div.wpcf7 > form' ).each( function() {
			var $form = $( this );

			$form.submit( function( event ) {
				if ( typeof window.FormData !== 'function' ) {
					return;
				}

				wpcf7.submit( $form );
				event.preventDefault();
			} );

			$( '.wpcf7-submit', $form ).after( '<span class="ajax-loader"></span>' );

			wpcf7.toggleSubmit( $form );

			$form.on( 'click', '.wpcf7-acceptance', function() {
				wpcf7.toggleSubmit( $form );
			} );

			// Exclusive Checkbox
			$( '.wpcf7-exclusive-checkbox', $form ).on( 'click', 'input:checkbox', function() {
				var name = $( this ).attr( 'name' );
				$form.find( 'input:checkbox[name="' + name + '"]' ).not( this ).prop( 'checked', false );
			} );

			// Free Text Option for Checkboxes and Radio Buttons
			$( '.wpcf7-list-item.has-free-text', $form ).each( function() {
				var $freetext = $( ':input.wpcf7-free-text', this );
				var $wrap = $( this ).closest( '.wpcf7-form-control' );

				if ( $( ':checkbox, :radio', this ).is( ':checked' ) ) {
					$freetext.prop( 'disabled', false );
				} else {
					$freetext.prop( 'disabled', true );
				}

				$wrap.on( 'change', ':checkbox, :radio', function() {
					var $cb = $( '.has-free-text', $wrap ).find( ':checkbox, :radio' );

					if ( $cb.is( ':checked' ) ) {
						$freetext.prop( 'disabled', false ).focus();
					} else {
						$freetext.prop( 'disabled', true );
					}
				} );
			} );

			// Placeholder Fallback
			if ( ! wpcf7.supportHtml5.placeholder ) {
				$( '[placeholder]', $form ).each( function() {
					$( this ).val( $( this ).attr( 'placeholder' ) );
					$( this ).addClass( 'placeheld' );

					$( this ).focus( function() {
						if ( $( this ).hasClass( 'placeheld' ) ) {
							$( this ).val( '' ).removeClass( 'placeheld' );
						}
					} );

					$( this ).blur( function() {
						if ( '' === $( this ).val() ) {
							$( this ).val( $( this ).attr( 'placeholder' ) );
							$( this ).addClass( 'placeheld' );
						}
					} );
				} );
			}

			if ( wpcf7.jqueryUi && ! wpcf7.supportHtml5.date ) {
				$form.find( 'input.wpcf7-date[type="date"]' ).each( function() {
					$( this ).datepicker( {
						dateFormat: 'yy-mm-dd',
						minDate: new Date( $( this ).attr( 'min' ) ),
						maxDate: new Date( $( this ).attr( 'max' ) )
					} );
				} );
			}

			if ( wpcf7.jqueryUi && ! wpcf7.supportHtml5.number ) {
				$form.find( 'input.wpcf7-number[type="number"]' ).each( function() {
					$( this ).spinner( {
						min: $( this ).attr( 'min' ),
						max: $( this ).attr( 'max' ),
						step: $( this ).attr( 'step' )
					} );
				} );
			}

			// Character Count
			$( '.wpcf7-character-count', $form ).each( function() {
				var $count = $( this );
				var name = $count.attr( 'data-target-name' );
				var down = $count.hasClass( 'down' );
				var starting = parseInt( $count.attr( 'data-starting-value' ), 10 );
				var maximum = parseInt( $count.attr( 'data-maximum-value' ), 10 );
				var minimum = parseInt( $count.attr( 'data-minimum-value' ), 10 );

				var updateCount = function( target ) {
					var $target = $( target );
					var length = $target.val().length;
					var count = down ? starting - length : length;
					$count.attr( 'data-current-value', count );
					$count.text( count );

					if ( maximum && maximum < length ) {
						$count.addClass( 'too-long' );
					} else {
						$count.removeClass( 'too-long' );
					}

					if ( minimum && length < minimum ) {
						$count.addClass( 'too-short' );
					} else {
						$count.removeClass( 'too-short' );
					}
				};

				$( ':input[name="' + name + '"]', $form ).each( function() {
					updateCount( this );

					$( this ).keyup( function() {
						updateCount( this );
					} );
				} );
			} );

			$form.on( 'change', '.wpcf7-validates-as-url', function() {
				var val = $.trim( $( this ).val() );

				// check the scheme part
				if ( val && ! val.match( /^[a-z][a-z0-9.+-]*:/i ) ) {
					val = val.replace( /^/+/, '' );
					val = 'http://' + val;
				}

				$( this ).val( val );
			} );

			if ( wpcf7.cached ) {
				wpcf7.refill( $form );
			}
		} );
	} );

}

wpcf7.init();

Luego, más tarde, puedo llamar a esto desde mi propio código:


if( typeof wpcf7 === 'object' && typeof wpcf7.init === 'function' ) {
  wpcf7.init();
}

(@konsument)

Hace 3 años, 7 meses

Hola, tengo el mismo problema en muchos sitios. ¿Podría explicar dónde ingresó el código?

(@nonverbla)

Hace 3 años, 7 meses

@konsument, subí el archivo scripts.js reescrito completo a mi servidor, puede descargarlo desde allí y reemplazar mi archivo con la versión /plugins/contact-form-7/includes/js/scripts.js:

http://test.rassohilber.com/wpcf7/scripts.js

(@konsument)

Hace 3 años, 6 meses

Muchas gracias. Mientras tanto, he encontrado una solución mucho más sencilla.

(@topitoconnectey)

Hace 3 años, 5 meses

Esta es la mejor forma:

`function initContactForm () {$ (‘div.wpcf7> form’) .each (function () {var $ form = $ (seo); wpcf7.initForm ($ form);

if (wpcf7.cached) {wpcf7.refill ($ formulario); }});

} `

(@azizultex)

hace 3 años

Gracias @topitoconnectey

(@cornhustlah)

Hace 2 años, 12 meses

gracias, @topitoconnectey

Parece que me han dicho que lo use incorrectamente $form.wpcf7InitForm() cuando realmente es wpcf7.initForm( $form )

sin embargo, ¿esta función ha cambiado recientemente? según parece wpcf7InitForm() ¿Alguna vez tuvo la función correcta …?

¿Solucionó tu problema??

0 / 0

Deja una respuesta 0

Tu dirección de correo electrónico no será publicada.