remove radio field type and add options for select field type form

This commit is contained in:
Eduardo humberto 2018-03-09 11:12:21 -03:00
parent 974eedba97
commit 8314fb993a
7 changed files with 93 additions and 4 deletions

View File

@ -14,6 +14,7 @@ import Relationship from '../../classes/field-types/relationship/Relationship.vu
import FormRelationship from '../../classes/field-types/relationship/FormRelationship.vue';
import FormCategory from '../../classes/field-types/category/FormCategory.vue';
import FormSelectbox from '../../classes/field-types/selectbox/FormSelectbox.vue';
import TaincanFormItem from '../../classes/field-types/tainacan-form-item.vue';
@ -43,8 +44,10 @@ Vue.component('tainacan-radio', Radio);
Vue.component('tainacan-numeric', Numeric);
Vue.component('tainacan-date', Date);
Vue.component('tainacan-relationship', Relationship);
Vue.component('tainacan-form-relationship', FormRelationship);
Vue.component('tainacan-form-category', FormCategory);
Vue.component('tainacan-form-selectbox', FormSelectbox);
Vue.component('tainacan-form-item', TaincanFormItem);
Vue.component('draggable', draggable);

View File

@ -89,6 +89,8 @@ return [
'label_select_category_input_type' => __('Input type', 'tainacan'),
'label_category_allow_new_terms' => __('Allow new terms', 'tainacan'),
'label_selectbox_init' => __('Select', 'tainacan'),
'label_options' => __('Insert options', 'tainacan'),
'label_attachments' => __('Attachments', 'tainacan'),
// Instructions. More complex sentences to guide user and placeholders
'instruction_dragndrop_fields_collection' => __('Drag and drop Fields here to add them to Collection.', 'tainacan'),

View File

@ -114,11 +114,11 @@ class Relationship extends Field_Type {
if (!empty($this->get_option('collection_id')) && !is_numeric($this->get_option('collection_id'))) {
return [
'collection_id' => 'Collection ID invalid'
'collection_id' => __('Collection ID invalid','tainacan')
];
} else if( empty($this->get_option('collection_id'))) {
return [
'collection_id' => 'Collection related is required'
'collection_id' => __('Collection related is required','tainacan')
];
}
return true;

View File

@ -0,0 +1,67 @@
<template>
<section
:listen="setError">
<b-field :label="$i18n.get('label_options')"
:type="optionType"
:message="optionMessage"
>
<b-taginput
v-model="options"
@input="emitValues()"
@focus="clear()"
icon="label"
:placeholder="$i18n.get('new')">
</b-taginput>
</b-field>
</section>
</template>
<script>
export default {
props: {
value: [ String, Object, Array ],
field: [ String, Object ],
errors: [ String, Object, Array ]
},
data() {
return {
optionType: '',
optionMessage: '',
options: []
}
},
created(){
if( this.value ) {
this.options = ( this.value.options ) ? this.value.options.split('\n') : [];
}
},
computed: {
setError(){
if( this.errors && this.errors.options !== '' ){
this.optionType = 'is-warning';
this.optionMessage = this.errors.options;
} else {
this.optionType = '';
this.optionMessage = '';
}
}
},
methods: {
clear(){
this.optionType = '';
this.optionMessage = '';
},
emitValues(){
this.$emit('input',{
options: ( this.options.length > 0 ) ? this.options.join('\n') : ''
})
}
}
}
</script>
<style scoped>
section{
margin-bottom: 10px;
}
</style>

View File

@ -14,6 +14,7 @@ class Selectbox extends Field_Type {
parent::__construct();
parent::set_primitive_type('string');
$this->component = 'tainacan-selectbox';
$this->form_component = 'tainacan-form-selectbox';
}
/**
@ -47,4 +48,21 @@ class Selectbox extends Field_Type {
</tr>
<?php
}
/**
* @param \Tainacan\Entities\Field $field
* @return array|bool true if is validate or array if has error
*/
public function validate_options(\Tainacan\Entities\Field $field) {
if ( !in_array($field->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
return true;
if ( empty($this->get_option('options')) ) {
return [
'options' => __('Options is required','tainacan')
];
}
return true;
}
}

View File

@ -87,7 +87,6 @@ $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Date');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Numeric');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Selectbox');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Relationship');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Radio');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Category');
global $Tainacan_Filters;

View File

@ -194,7 +194,7 @@ class Fields extends TAINACAN_UnitTestCase {
*/
function test_metadata_field_type(){
global $Tainacan_Fields;
$this->assertEquals( 8, sizeof( $Tainacan_Fields->fetch_field_types() ) );
$this->assertEquals( 7, sizeof( $Tainacan_Fields->fetch_field_types() ) );
}