What am I doing wrong coding a button on a WIX website to change a field value of a specific field in a WIX dataset? - onclick

I have this code I have been tinkering around with but from the syntax, I have been trying to change my TAGID to 1 in the dataset. Currently it is 0, I have been trying different things just to change the data in the dataset, nothing seems to be working..
$w.onReady( () => {
$w("#dataset1").onReady( () => {
$w("#dataset1").setFieldValue($w("#TagID", "1"));
$w("#dataset1").save()
} );
} );

Related

Appending custom Query to a Wordpress specific menu

I'm creating a WP menu, which should take the user to the current page, and just append a query to end of it.
So, for example I'm on a custom page:
example.com/group/fans
So the current menu items which links to:
/?query1
/?query2
/?query3
Should be appended to the current page:
example.com/group/fans/?query1
And same thing for different pages, with the Same menu items.
I've searched for many solutions but couldn't find one, Any suggestions?
Have you tried the post_link filter? I think something like below might be what you are looking for:
add_filter('post_link', function ($link) {
$pattern = 'group/fans';
$is_custom_query = strpos($link, $pattern) !== false;
if ($is_custom_query) {
return add_query_arg([
'query1' => 'someValue',
'query2' => 'someValue2'
], $link);
}
return $link;
});

ACF default field group settings for "hide on screen"

I would like to set default settings for style and hide on screen settings within the field group settings.
I've found posts talking about modifying settings for individual ACF fields like the WYSIWYG or image fields like so.
add_filter( 'acf/get_valid_field', 'change_post_content_type');
function change_post_content_type( $field ) {
if($field['type'] == 'wysiwyg') {
$field['tabs'] = 'visual';
$field['media_upload'] = 0;
}
if($field['type'] == 'image') {
$field['preview_size'] = 'small';
}
if($field['type'] == 'style') {
$field['style'] = 'seamless';
}
return $field;
}
Using this overrides whatever is selected rather than setting the value as default but it's good enough for what I need.
The image and WYSIWG field work fine but I can't get it working on the field group setting fields. I don't think the $field['type'] == 'style' is correct but as it doesn't follow the same structure as the other fields I don't know what I should be using.
Any ideas?
update
I've found this but I can't figure out how to use it. The following doesn't work
add_action('acf/render_field_group_settings', 'change_field_group_settings', 10, 1);
function change_field_group_settings( $field_group ) {
$field_group['style'] = 'seemless';
$field_group['hide_on_screen'] = array('the_content');
return $field_group;
}
You may need change your syntax to use proper formatting for style and hide_on_screen, for example:
'hide_on_screen' => array(
0 => 'the_content',
),
Best practice would be to create a new Field Group in your WP CMS, publish it, and navigate to:
Custom Fields > Tools > (check the box for your Field Group) > Generate PHP
That way you can view the proper output.

Drupal Hook_Block_View perform action on button click

I am learning drupal and am trying to add some extra features to a module I've made following a tutorial
I have one block 'History' which shows the last x pages you've viewed.
Now I've made a second block with a button 'clear history', but I can't figure out how to make the set_value('trails_block_history','0') happen when my button is clicked (which would clear my history in the database)
anybody who can help me out here?
My blocks:
function trails_block_info() {
$blocks['history'] = array(
'info' => t('History'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['clearHist'] = array(
'info' => t('Clear history'),
'cache' => DRUPAL_NO_CACHE
);
return $blocks;
}
hook block save:
function trails_block_save($delta = '', $edit = array()) {
variable_set('trails_block_num', $edit['trails_block_num']);
variable_set('trails_block_granularity',$edit['trails_block_granularity']);
}
and the problem:
function trails_block_view($delta = '') {
...
case 'clearHist' :
{
$block['subject'] = 'Clear History';
$block['content'] = '<button>clear history</button>';
} break;
...
Still a student and reaaally new to this (started the module-coding this morning) so sorry if this seems like a stupid question (which it most probably is) but I just can't find it..
Have made another extra feature on the module allready, so I want this one to work as well!
You should use Forms API to create a form with submit button. Then clear your history when form is submitted. More info here and some example code here

How do I alter the #weight of the content generated by the upload.module?

On my Drupal powered website, I want to list available downloads at the top of a node page (within a narrow float:right <div>), not at the bottom where they normally appear.
Within my theme, I've overridden the theme_upload_attachments() function to generate a <div> of width 40%, but this is showing up at the bottom of the page.
Within the upload.module file is code that controls where the attachments are listed on the page:
// function upload_nodeapi(), line #284 of upload.module
$node->content['files'] = array(
'#value' => theme('upload_attachments', $node->files),
'#weight' => 50,
);
If I manually hack this #weight to -1, my custom list of attachments shows where I want, floating at the righthand side of the top of the content area.
However, I don't want to manually hack the core file upload.module, as my changes will be lost next time I apply an upgrade (say, for a security patch).
How/Where do I modify the #weight of content['files'] within my theme code?
Or, am I going about this the wrong way?
You'll need a module to do this, not just a theme. A module can implement hook_nodeapi(), which will give it a chance to change the contents of that $node->content array before it's rendered. If your module is named 'upload_tweaker' for example, you'd use the following function:
function upload_tweaker_nodeapi(&$node, $op) {
if ($op == 'view') {
$node->content['files']['#weight'] = -1;
}
}
Each module gets a crack at changing the node during this 'nodeapi' event; if you want to change the stuff that's added by one module, you need to make sure that your module loads after it. This can be done by naming it something like 'zzz', or by changing its "weight" field in the system table of your site's database. Modules can be weighted just like form elements.
api.drupal.org has more information.
For those who uses CCK and want to alter body weight:
CCK module uses pre_render function
/**
* Pre-render callback to adjust weights of non-CCK fields.
*/
function content_alter_extra_weights($elements) {
if (isset($elements['#content_extra_fields'])) {
foreach ($elements['#content_extra_fields'] as $key => $value) {
// Some core 'fields' use a different key in node forms and in 'view'
// render arrays. Check we're not on a form first.
if (!isset($elements['#build_id']) && isset($value['view']) && isset($elements[$value['view']])) {
$elements[$value['view']]['#weight'] = $value['weight'];
}
elseif (isset($elements[$key])) {
$elements[$key]['#weight'] = $value['weight'];
}
}
}
return $elements;
}
So due to this callback you are not able to alter weight using normal behavior.
You should do this:
function YOUR_MODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
// Only for node pages.
if ($op == 'view' && $a4) {
$body_weight = 15 // Any weight.
$node->content['#content_extra_fields']['body']['weight'] = $body_weight; // This value CCK module will use to alter body weight in the callback from above.
}
}

Drupal Views2 Exposed Form how to change

I have a View with an exposed form . I am trying to a few things on it. Ideally I would like to have a dropdown that fires the form with no button. If that is not possible then I would like to have the button text something different than apply.
I hacked it for now and change views_form in views.module but that does not seem like the right way to do it. I only have one exposed form right now, but what if I add more?
Please see http://www.wiredvillage.ca/News for my example.
I am poking around drupal.org and seeing others with the same problem but no solutions so far. Not sure where the best place to get Drupal help is.
Here is the change I made so far:
function views_exposed_form(&$form_state) {
// Make sure that we validate because this form might be submitted
// multiple times per page.
$form_state['must_validate'] = TRUE;
$view = &$form_state['view'];
$display = &$form_state['display'];
$form_state['input'] = $view->get_exposed_input();
// Let form plugins know this is for exposed widgets.
$form_state['exposed'] = TRUE;
$form['#info'] = array();
if (!variable_get('clean_url', FALSE)) {
$form['q'] = array(
'#type' => 'hidden',
'#value' => $view->get_url(),
);
}
// Go through each filter and let it generate its info.
foreach ($view->filter as $id => $filter) {
$view->filter[$id]->exposed_form($form, $form_state);
if ($info = $view->filter[$id]->exposed_info()) {
$form['#info']['filter-' . $id] = $info;
}
}
// I CHANGED The VALUE OF THIS SUBMIT BUTTON TO GO
$form['submit'] = array(
'#name' => '', // prevent from showing up in $_GET.
'#type' => 'submit',
'#value' => t('go'),
);
$form['#action'] = url($view->get_url());
$form['#theme'] = views_theme_functions('views_exposed_form', $view, $display);
$form['#id'] = views_css_safe('views_exposed_form-' . check_plain($view->name) . '-' . check_plain($display->id));
// $form['#attributes']['class'] = array('views-exposed-form');
// If using AJAX, we need the form plugin.
if ($view->use_ajax) {
drupal_add_js('misc/jquery.form.js');
}
views_add_js('dependent');
return $form;
}
Or, you could use a preprocess function to alter the form even before it is build. I wanted to change the text on the button, so I did this:
function MYTHEME_preprocess_views_exposed_form(&$vars, $hook) {
// only alter the jobs search exposed filter form
if ($vars['form']['#id'] == 'views-exposed-form-jobs-search-page-1') {
// Change the text on the submit button
$vars['form']['submit']['#value'] = t('Search');
// Rebuild the rendered version (submit button, rest remains unchanged)
unset($vars['form']['submit']['#printed']);
$vars['button'] = drupal_render($vars['form']['submit']);
}
}
If you want the drop-down to fire, I'd use JavaScript instead of hacking the module as Eaton suggests.
Basically, you can modify the text with hook_form_alter as Eaton suggests, then use in the same hook_form_alter, add a call to drupal_add_js with your custom JS which hides the button and submits the form on the onChange handler of the select drop-down. You want that submit button there for those 10% of users for whom the JS fails.
Both of the above are fine but I found out that altering the form might not always lead to desirable results, mainly because exposed filters are themed using a specifc theme template. The proper way of changing the theme would be to override the views-exposed-form.tpl file in your theme's folder. Bear in mind that this will apply to all exposed filter forms, to theme a specific one, you will need to use a different name for that filename, like:
views-exposed-form--TITLE--DISPLAY.tpl.php
views-exposed-form--TITLE.tpl.php
and some others, you can check the Theme: Information section of your views for template naming conventions.
This module provides an auto-submit among other things http://drupal.org/project/views_hacks
This module is great to improving exposed filters http://drupal.org/project/better_exposed_filters
You should be able to use hook_form_alter() (http://api.drupal.org/api/function/hook_form_alter) to change the form as it's built, modifying the fields in question when that particular view is being displayed. You can nuke the submit button, add a #theme function that calls the drupal_add_js() function, and so on.
As long as the GET params come in the way views expect them, everything will work fine -- it was designed that way to allow bookmarking of pages with exposed filter settings, etc. The important part is to make sure you're doing the form mangling in your own module's hook_form_alter() function, so that it won't make other views driven stuff choke.

Resources