GithubHelp home page GithubHelp logo

Comments (12)

carst avatar carst commented on June 19, 2024

I second this. The way it is setup now, using a related field means there always is a value.
It would be much more useful if there would be a blank option.

from magic-fields-2.

EivindFS avatar EivindFS commented on June 19, 2024

Hi carst,

I have edited the code for this field myself if you are interested. Just take this code and paste it into your magic fields directory/fields_type/related_type_field/related_type_field.php

description = __("This field allows to do relations with other post type",$mf_domain); } public function _options(){ global $mf_domain; ``` $posttypes = $this->mf_get_post_types(); $select = array(); foreach($posttypes as $k => $v){ $select[$k] = $v->label; } $data = array( 'option' => array( 'post_type' => array( 'type' => 'select', 'id' => 'post_type', 'label' => __('Related Type Panel (Post type)',$mf_domain), 'name' => 'mf_field[option][post_type]', 'default' => '', 'options' => $select, 'add_empty' => false, 'description' => '', 'value' => '', 'div_class' => '', 'class' => '' ), 'field_order' => array( 'type' => 'select', 'id' => 'field_order', 'label' => __('Field for order of Related type',$mf_domain), 'name' => 'mf_field[option][field_order]', 'default' => '', 'options' => array('id' => 'ID','title' =>'Title'), 'add_empty' => false, 'description' => '', 'value' => '', 'div_class' => '', 'class' => '' ), 'order' => array( 'type' => 'select', 'id' => 'order', 'label' => __('Order of Related type',$mf_domain), 'name' => 'mf_field[option][order]', 'default' => '', 'options' => array('asc' => 'ASC','desc' =>'DESC'), 'add_empty' => false, 'description' => '', 'value' => '', 'div_class' => '', 'class' => '' ), 'notype' => array( 'type' => 'text', 'id' => 'notype', 'label' => __('Default option (when no related type has been set)',$mf_domain), 'name' => 'mf_field[option][notype]', 'default' => '', 'options' => '', 'add_empty' => false, 'description' => '', 'value' => '', 'div_class' => '', 'class' => '' ) ) ); return $data; ``` } public function display_field( $field, $group_index = 1, $field_index = 1 ) { $output = ''; ``` $type = $field['options']->post_type; $order = $field['options']->order; $field_order = $field['options']->field_order; $notype = $field['options']->notype; $options = get_posts( sprintf("post_type=%s&numberposts=-1&order=%s&orderby=%s",$type,$order,$field_order) ); $output = '
'; $value = $field['input_value']; $output .= sprintf('',$field['input_id'],$field['input_name']); //Added by Eivind $output .= "$notype"; foreach($options as $option) { $check = ($option->ID == $value) ? 'selected="selected"' : ''; $output .= sprintf('%s', esc_attr($option->ID), $check, esc_attr($option->post_title) ); } $output .= ''; $output .= '
'; return $output; ``` } } ?>

It is really easy to customize fields in this version. It's quite brilliant really.

Eivind

from magic-fields-2.

EivindFS avatar EivindFS commented on June 19, 2024

Ignore all the weird stuff github does to my code. Just take out all that's between

from magic-fields-2.

carst avatar carst commented on June 19, 2024

Hey thanks! In the meantime I worked around the problem by just adding an option with a zero value and a type of '(none)'.

What you're doing does make more sense however, being able to choose a name for the empty type.

from magic-fields-2.

EivindFS avatar EivindFS commented on June 19, 2024

Hi Carst,

How exactly do you add an option to a related types field? I can't see that being possible anywhere. Care to explain?

Thanks

from magic-fields-2.

carst avatar carst commented on June 19, 2024

Hi Eivind, well exactly like you did it, by writing:

// adds an empty value
$output .= sprintf('<option value="0">(none)</option>');

from magic-fields-2.

EivindFS avatar EivindFS commented on June 19, 2024

Oh, you did it with code as well then. That clarifies it.

Cheers.

E

from magic-fields-2.

gnuget avatar gnuget commented on June 19, 2024

Done.

Thank you @EivindFS and @carst :-)

@EivindFS the next time to you want to share some code with us can you use gist (https://gist.github.com/) ? thanks

from magic-fields-2.

Antox-xx avatar Antox-xx commented on June 19, 2024

Also the same issue with a Dropdown Field

from magic-fields-2.

gnuget avatar gnuget commented on June 19, 2024

IMHO is not necessary add a "None" option for Dropdown field because in that field you set the options by hand and you can set there the "None" value

from magic-fields-2.

Antox-xx avatar Antox-xx commented on June 19, 2024

Therefore that field always will be set, not empty. And "Required" option will not work correctly, and I will have to do some code to display nothing instead "None".

from magic-fields-2.

gnuget avatar gnuget commented on June 19, 2024

Yeah, you are right.

I'm going to work on this.

from magic-fields-2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.