How to hide a fieldset (tab) in Plone add/edit form - plone

I have some code in dexterity content type, as below:
form.fieldset(
'transitionsLog',
label=_(u"Transitions Log"),
fields=['t_log']
)
form.mode(t_log='hidden')
t_log = schema.TextLine(
title=_(u'Transitions log'),
)
In add/edit form, the field t_log hide but fieldset tab 'Transitions Log' still show at form, as above...
I have no idea to hide "Transitions Log" tab in add/edit form,
How can I do ?

Since the fields are still rendered in hidden mode, the fieldset still exists.
If you want to completely omit the fieldset you need to omit all fields in the fieldset. This can be achieved using the omitted directive form.omitted.
form.fieldset(
'transitionsLog',
label=_(u"Transitions Log"),
fields=['t_log']
)
form.omitted('t_log') # This will also omit your fieldset
t_log = schema.TextLine(
title=_(u'Transitions log'),
)

I find a right way as below to omitted field in Custom Add/Edit Form:
from plone.z3cform.fieldsets.utils import remove
...
def updateWidgets(self):
remove(self, 't_log')
super(CustomEditForm, self).updateWidgets()

Related

TypeRocket - Conditional fields

I've got a Typerocket form (within Wordpress) and I'm trying to make a conditional field.
Like if the Type field is Image, show and Image field afterwards and if the Type field is Quote have a text (editor) field afterwards.
I can't find anything about Conditional fields in Typerocket's doc.
Here's what I got right now.
echo $form->repeater('pj_images_du_projet')->setLabel("Images du projet")->setFields([
$form->select('Type')->setOptions([
"Image"=>'image',
"Vidéo"=>'video',
"Témoignage"=>'temoignage'
]), //Type is what chooses what fields are below. Options are Image, Video or Testimonial
$form->image('image')->setLabel('Image'), //image only
$form->text('video')->setLabel('Vidéo'), //video only
$form->toggle('autoplay')->setLabel('Autoplay'), //video only
$form->textarea('temoignage')->setLabel('Témoignage'), //temoignage only
$form->text('auteur')->setLabel('Auteur'), //temoignage only
]);
Created a JS that does the work.
JS
jQuery('body').ready(function(){
jQuery("body").on('change','.is-conditional-selector',function(){px_redoConditionals();})
px_redoConditionals();
})
function px_redoConditionals(){
jQuery('body').find('.is-conditional-selector').each(function(){
var repeater = jQuery(this).parent().parent().parent();
console.log(repeater.attr('class'));
repeater.find('.is-conditional').removeClass('px-show');
//console.log(jQuery(this).val());
repeater.find('.is-conditional.is-conditional-'+jQuery(this).val()).addClass('px-show');
})
}
CSS
.is-conditional:not(.px-show){
display:none !important;
}
And then I add this to the select that changes which section is shown
->setAttribute('class','is-conditional-selector')
And this on the fields that need to be shown or hidden
->setAttribute('class','is-conditional is-conditional-[value of the select to show this]'),

How can I hide/show advanced custom fields based on selection of a select field?

I created some advanced custom fields. One of them is a select field, where you can choose between sale and charter.
I want to hide/show some of my advanced custom fields based on what is currently selected (sale or charter).
How can I do this?
ACf Image
As shown in image (Click link) there is an option in the ACF to show fields conditionally based on other fields value whether it is Checkbox or Select box.
The other answer covers the back end. For the front end template, something like this:
if (get_field('select_field_name') == 'sale'){
//show some stuff i.e. the_field('field_name');
}
elseif (get_field('select_field_name') == 'charter') {
//show other fields
}
else {
//maybe do something here
}

How make single page for WP_List_Table edit?

How I can create admin page, to edit single item from custom table WP_List_Table?
Data: Custom DB Table, on admin I have add menu item with method which build this table through WP_List_Table.
There I want to create 'manage' button, to manage single item from this table.
How can I do this?
Is there some action hook
or i have to just add second class
Or like menu item
I have try add like menu item, But how can I add it without adding to the menu? add_submenu_page with parent slug = null is it really clear WP solution?
For my situation good solution:
if ( array_key_exists( 'single', $_REQUEST ) ) {
//function to process single item
} else {
//Create an instance of our package class...
$withdraw = new Class_Table();
//Fetch, prepare, sort, and filter our data...
$withdraw->prepare_items();
}

Wordpress widget for post specific content in sidebar

I am looking for a wordpress plugin that will allow me to add a paragraph to the sidebar that is specific to the blog post. I would need to be able to add that text when creating the post. Is there something out there like that? I have been unsuccessful in searches.
Thanks
This can be easily solved using Custom Fields, the Text Widget and a Shortcode.
This bit of code goes in the theme's functions.php or, preferable, within a custom plugin.
1) Enable shortcodes for the Text Widget
add_filter( 'widget_text', 'do_shortcode' );
2) Define the shortcode, read comments for details
add_shortcode( 'mytext', 'so_13735174_custom_text_widget' );
function so_13735174_custom_text_widget( $atts, $content = null )
{
global $post;
// $post contains lots of info
// Using $post->ID many more can be retrieved
// Here, we are getting the Custom Field named "text"
$html = get_post_meta( $post->ID, 'text', true );
// Custom Field not set or empty, print nothing
if( !isset( $html ) || '' == $html )
return '';
// Print Custom Field
return $html;
}
3) Add a Text Widget in the desired sidebar.
Leave the title empty and put the Shortcode in the content: [mytext].
4) Now each page or post with a Custom Field named text will have its value printed in the Widget.
5) The $html can get fancy and multiple Custom Fields can be used.
This isn't something that I've ever personally done, but try this.
Summary: You will add the a paragraph using a custom field, then display it in a widget.
Details:
First, make sure custom fields are enabled. Edit a post, then click
the "screen options" at the top right of the page. If "Custom
Fields" isn't checked, check it. You should now see a custom field
area below the post editor.
Come up with a name for your custom field. Perhaps
"extra_paragraph". Now put that in the "name" field in the custom
field area.
Write your paragraph in the "value" field the custom field area.
Install the Custom Field Widget plugin, set it to display this
new "extra_paragraph" field. (widget appears to be untested with newer versions of Wordpress so cross your fingers!)
Now when you write or edit posts you should see this "extra_paragraph" field as an option in the "name" dropdown.

Wordpress: Editing 2 columns

I would like some advice on the following issue:
What would be the best way to edit a page that has 2x columns via the editor?
You can try it with the Custom Field Template.
For the first column you can use the default editor of Wordpress and for the second you can create a custom field in which the plugin shows a textarea with TinyMCE support.
Posible code for the "custom field template" to show a textarea in a custom field area:
[column_2]
type = textarea
rows = 4
cols = 40
tinyMCE = true
htmlEditor = true
mediaButton = true
(you have to enter that code in wp-admin panel of the plugin).
To get the data from the custom field in your the template-file you can use the
get_post_custom_values function:
//returns an array
$colum_2_content = get_post_custom_values("column_2", $post_id);
echo $colum_2_content [0];

Resources