Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related fields issue #11

Closed
EivindFS opened this issue Aug 3, 2011 · 12 comments
Closed

Related fields issue #11

EivindFS opened this issue Aug 3, 2011 · 12 comments

Comments

@EivindFS
Copy link

EivindFS commented Aug 3, 2011

Hi again,

There is no unselected state for the related field. So even though no related field is set, it will appear as if the first one is.

I consider this a bug. It would be great if the backend interface gave us the option of setting the text for the dropdown's unselected state ourselves.

Thanks!
Eivind

@carst
Copy link

carst commented Aug 8, 2011

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.

@EivindFS
Copy link
Author

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

@EivindFS
Copy link
Author

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

@carst
Copy link

carst commented Aug 19, 2011

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.

@EivindFS
Copy link
Author

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

@carst
Copy link

carst commented Aug 22, 2011

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

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

@EivindFS
Copy link
Author

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

Cheers.

E

@gnuget
Copy link
Member

gnuget commented Aug 30, 2011

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

@gnuget gnuget closed this as completed in a41a2ea Aug 30, 2011
@Antox-xx
Copy link

Also the same issue with a Dropdown Field

@gnuget
Copy link
Member

gnuget commented Aug 31, 2011

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

@Antox-xx
Copy link

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".

@gnuget
Copy link
Member

gnuget commented Aug 31, 2011

Yeah, you are right.

I'm going to work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants