Skip to content
Snippets Groups Projects
Commit e9c36523 authored by Piotr Po's avatar Piotr Po
Browse files

Merge branch 'scope/fields' into 'master'

scope: added new field

See merge request !14
parents ec574cc6 4c862951
No related branches found
No related tags found
1 merge request!14scope: added new field
Pipeline #5755 passed with stages
in 1 minute and 35 seconds
{ {
"name": "wpdesk/wp-forms", "name": "wpdesk/wp-forms",
"description": "WP Forms",
"authors": [ "authors": [
{ {
"name": "Marcin", "name": "Marcin",
...@@ -8,6 +9,10 @@ ...@@ -8,6 +9,10 @@
{ {
"name": "Krzysiek", "name": "Krzysiek",
"email": "krzysiek@wpdesk.pl" "email": "krzysiek@wpdesk.pl"
},
{
"name": "Piotr Potrebka",
"email": "piotr.potrebka@wpdesk.pl"
} }
], ],
"require": { "require": {
...@@ -31,6 +36,13 @@ ...@@ -31,6 +36,13 @@
}, },
"autoload-dev": { "autoload-dev": {
}, },
"extra": {
"text-domain": "wp-forms",
"translations-folder": "lang",
"po-files": {
"pl_PL": "pl_PL.po"
}
},
"scripts": { "scripts": {
"phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never", "phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never",
"phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage", "phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage",
......
File added
msgid ""
msgstr ""
"Project-Id-Version: WP Forms\n"
"POT-Creation-Date: 2021-05-24 10:07+0200\n"
"PO-Revision-Date: 2021-05-24 10:07+0200\n"
"Last-Translator: Piotr Po <potreb@gmail.com>\n"
"Language-Team: Piotr Potrebka <piotr.potrebka@gmail.com>\n"
"Language: pl_PL\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.3\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
"|| n%100>=20) ? 1 : 2);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
"_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPath-1: src\n"
"X-Poedit-SearchPathExcluded-0: *.js\n"
"X-Poedit-SearchPathExcluded-1: vendor\n"
"X-Poedit-SearchPathExcluded-2: vendor_prefixed\n"
#: templates/input-image.php:24
msgid "Set image"
msgstr "Wstaw obraz"
#: templates/input-image.php:29
msgid "Remove image"
msgstr "Usuń obraz"
#: templates/input-image.php:50
msgid "Select or Upload Media"
msgstr "Wybierz lub prześlij media"
#: templates/input-image.php:52
msgid "Use this media"
msgstr "Wybierz"
#: templates/product-select.php:13
msgid "Search for a product&hellip;"
msgstr "Szukaj produktu&hellip;"
<?php
namespace WPDesk\Forms\Field;
class ImageInputField extends \WPDesk\Forms\Field\BasicField {
public function __construct() {
parent::__construct();
$this->set_default_value( '' );
$this->set_attribute( 'type', 'text' );
}
/**
* @return string
*/
public function get_template_name() {
return 'input-image';
}
}
<?php
namespace WPDesk\Forms\Field;
class MultipleInputTextField extends InputTextField {
/**
* @return string
*/
public function get_template_name() {
return 'input-text-multiple';
}
}
<?php
/**
* @var \WPDesk\Forms\Field $field
* @var string $name_prefix
* @var string $value
*/
?>
<?php
$media_container_id = 'media_' . sanitize_key( $field->get_id() );
?>
<div class="media-input-wrapper" id="<?php echo $media_container_id; ?>">
<input type="hidden" class="image-field-value" value="<?php echo \esc_html( $value ); ?>"
name="<?php echo \esc_attr( $name_prefix ) . '[' . \esc_attr( $field->get_name() ) . ']'; ?>"
id="<?php echo \esc_attr( $field->get_id() ); ?>"/>
<div class="custom-img-container">
<?php if ( $value ) : ?>
<img src="<?php echo $value ?>" alt="" width="100"/>
<?php endif; ?>
</div>
<p class="hide-if-no-js">
<a class="upload-custom-img <?php if ( $value ) {
echo 'hidden';
} ?>" href="<?php echo $value ?>">
<?php _e( 'Set image', 'wp-forms' ) ?>
</a>
<a class="delete-custom-img <?php if ( ! $value ) {
echo 'hidden';
} ?>" href="#">
<?php _e( 'Remove image', 'wp-forms' ) ?>
</a>
</p>
</div>
<script>
jQuery( function ( $ ) {
var frame,
metaBox = $( '#<?php echo $media_container_id; ?>' ),
addImgLink = metaBox.find( '.upload-custom-img' ),
delImgLink = metaBox.find( '.delete-custom-img' ),
imgContainer = metaBox.find( '.custom-img-container' ),
imgIdInput = metaBox.find( '.image-field-value' );
addImgLink.on( 'click', function ( event ) {
event.preventDefault();
if ( frame ) {
frame.open();
return;
}
frame = wp.media( {
title: <?php _e( 'Select or Upload Media', 'wp-forms' ); ?>,
button: {
text: <?php _e( 'Use this media', 'wp-forms' ); ?>
},
library: {
type: ['image']
},
multiple: false
} );
frame.on( 'select', function () {
var attachment = frame.state().get( 'selection' ).first().toJSON();
imgContainer.append( '<img src="' + attachment.url + '" alt="" width="100" />' );
imgIdInput.val( attachment.url );
addImgLink.addClass( 'hidden' );
delImgLink.removeClass( 'hidden' );
} );
frame.open();
} );
delImgLink.on( 'click', function () {
imgContainer.html( '' );
addImgLink.removeClass( 'hidden' );
delImgLink.addClass( 'hidden' );
imgIdInput.val( '' );
return false;
} );
} );
</script>
<?php
/**
* @var \WPDesk\Forms\Field $field
* @var \WPDesk\View\Renderer\Renderer $renderer
* @var string $name_prefix
* @var string $value
*
* @var string $template_name Real field template.
*
*/
?>
<?php
if( empty( $value ) || is_string( $value ) ) {
$input_values[] = '';
} else {
$input_values = $value;
}
?>
<div class="clone-element-container">
<?php foreach( $input_values as $text_value ): ?>
<?php if (!\in_array($field->get_type(), ['number', 'text', 'hidden'])): ?>
<input type="hidden" name="<?php echo $name_prefix.'['.$field->get_name().']'; ?>" value="no"/>
<?php endif; ?>
<?php if ($field->get_type() === 'checkbox' && $field->has_sublabel()): ?><label><?php endif; ?>
<div class="clone-wrapper">
<input
type="<?php echo \esc_attr($field->get_type()); ?>"
name="<?php echo \esc_attr($name_prefix).'['.\esc_attr($field->get_name()).'][]'; ?>"
id="<?php echo \esc_attr($field->get_id()); ?>"
<?php if ($field->has_classes()): ?>
class="<?php echo \esc_attr($field->get_classes()); ?>"
<?php endif; ?>
<?php if ($field->get_type() === 'text' && $field->has_placeholder()):?>
placeholder="<?php echo \esc_html($field->get_placeholder());?>"
<?php endif; ?>
<?php foreach ($field->get_attributes() as $key => $atr_val):
echo $key.'="'.\esc_attr($atr_val).'"'; ?>
<?php endforeach; ?>
<?php if ($field->is_required()): ?>required="required"<?php endif; ?>
<?php if ($field->is_disabled()): ?>disabled="disabled"<?php endif; ?>
<?php if ($field->is_readonly()): ?>readonly="readonly"<?php endif; ?>
<?php if (\in_array($field->get_type(), ['number', 'text', 'hidden'])): ?>
value="<?php echo \esc_html($text_value); ?>"
<?php else: ?>
value="yes"
<?php if ($value === 'yes'): ?>
checked="checked"
<?php endif; ?>
<?php endif; ?>
/>
<span class="add-field"><span class="dashicons dashicons-plus-alt"></span></span>
<span class="remove-field hidden"><span class="dashicons dashicons-remove"></span></span>
</div>
<?php if ($field->get_type() === 'checkbox' && $field->has_sublabel()): ?>
<?php echo \esc_html($field->get_sublabel()); ?></label>
<?php endif; ?>
<?php endforeach; ?>
</div>
<style>
.clone-element-container .clone-wrapper .add-field {
display: none;
}
.clone-element-container .clone-wrapper:first-child .add-field {
display: inline-block;
}
.clone-element-container .clone-wrapper .remove-field {
display: inline-block;
}
.clone-element-container .clone-wrapper:first-child .remove-field {
display: none;
}
</style>
<script>
jQuery( function ( $ ) {
var add_field = jQuery( '.add-field' );
if ( add_field.length ) {
add_field.click( function ( e ) {
let html = jQuery( this ).closest( '.clone-wrapper' ).clone();
html.find( 'input' ).val( '' );
jQuery( this ).closest( '.clone-wrapper' ).after( html );
} )
jQuery( '.clone-element-container' ).on( "click", ".remove-field", function ( e ) {
let is_disabled = jQuery( this ).hasClass( 'field-disabled' );
if ( !is_disabled ) {
jQuery( this ).closest( '.clone-wrapper' ).remove();
}
} )
jQuery( '.form-table' ).find( 'input,select' ).each( function ( i, v ) {
let disabled = jQuery( this ).attr( 'data-disabled' );
if ( disabled === 'yes' ) {
jQuery( this ).attr( 'disabled', 'disabled' )
jQuery( this ).parent().addClass( 'field-disabled' );
}
} );
}
} );
</script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment