Drupal StackExchange

What is the best way to add a confirmation tooltip to the remove button of a managed_file field?

1 month 3 weeks ago
Another Update

I'm trying to implement the solution found here: Intercept click event on a button, ask for confirmation, then proceed, but the remove button still submits normally. I know my JS is targeting the correct element, because I can change other attributes on it like the background color.

Here's my form:

function form_experiments_01() { $form['#attached']['js'] = array( drupal_get_path('module', 'form_experiments') . '/js/form_experiments.js', ); $form['managed_files'] = array( '#type' => 'fieldset', '#title' => t('Managed Files'), ); $num_docs = 3; for ($i = 1; $i <= $num_docs; $i++) { $form['managed_files'][$i] = array( '#type' => 'managed_file', '#title' => 'Managed File ' . $i, ); } $form['submit'] = array( '#type' => 'submit', '#value' => 'Submit', ); return $form; }

Here's my javascript:

(function ($) { Drupal.behaviors.managedFileAutoUpload = { attach: function(context, settings) { $('.form-item input.form-submit[value=Upload]', context).hide(); $('.form-item input.form-file', context).change(function() { $parent = $(this).closest('.form-item'); //setTimeout to allow for validation //would prefer an event, but there isn't one setTimeout(function() { if(!$('.error', $parent).length) { $('input.form-submit[value=Upload]', $parent).mousedown(); } }, 100); }); } }; Drupal.behaviors.managedFileConfirmRemove = { attach: function(context, settings) { var myButton = $('.form-item input.form-submit[value=Remove]', context); if (myButton.length > 0) { var myClick = null; //get a list of jQuery handlers bound to the click event var jQueryHandlers = myButton.data('events').click; console.log(jQueryHandlers); //grab the first jquery function bound to this event $.each(jQueryHandlers,function(i,f) { myClick = f.handler; return false; }); //unbind the original myButton.unbind('click'); //bind the modified one myButton.click(function(){ if(window.confirm("Are You Sure?")){ myClick(); } else { return false; } }); } } } })(jQuery); Update

After some more research I found this question. This is what I was trying to ask but didn't know how to word.

Intercept click event on a button, ask for confirmation, then proceed

I'll implement this solution and post a resolution once I've got it working.

Description

I would like to add a confirmation tooltip when the "remove" button is clicked on my managed_file field.

I would like to do something similar to this:

What is the best way to do that?

Possible Solution?

So far, I'm thinking I could probably use javascript to hide the remove button and instead display my own button. Then when my button is clicked, I can trigger a popup that contains a second custom button to cancel and the remove button that I originally hid.

I'm worried that this solution is a bit messy. Is there a more elegant way to do this? Can I get a similar behavior without hiding the original remove button?

Similar Questions

I'm not sure if these apply to my use-case since I'm working with a managed_file field. So far, I've been unable to implement similar solutions without the default behavior of the remove button interfering.

Resources
ssteigen

How to translate field collection which has unlimited values?

1 month 3 weeks ago

My configuration: latest dev entity translation and field collection module + patch.

I tried:

1. Entity translation is on just for taxonomy term and node, but not for field collection (it triggers notice: not translatable because of valid base path...) I have taxonomy term with field collection (unlimited value). In FC field there are just two fields that needs to be translated. FC and fields inside FC have set "enable field translation by users".

With these settings I can create a term, set values to FC fields on default language and save. Then I can translate and set values to FC fields for second language and save. All good when checking if it did saved 2 different values - each for own language. Then I create view which is used on panels and is using termID as context filter. View has relationship on FC field and I added FC fields to show. What happens: on view when I preview with term ID (context filter) I get correct result for the language in URL (en/admin/structure/views..). Also when I change URL to another language prefix I get translated fields in that language. But translated fields don't show on actual term pages.

2. Beside what I described in 1, I also enable entity translation for field collection. Notice about valid base path is still there, but I applied patch and i don't get errors when adding or translating FC.

With this configuration I create fresh FC with new fields and enable field translation for all of them. On term I set some values for FC fields and save it. I repeat this step when translating. But when I save translations and open them they are empty. On the next fill they remain. But the view for this configuration is still not showing right values for selected languages.

Does anyone have any hint what I am doing wrong? I really need to fix this issue on my site and I am short on time.

What I need is to translate FC field (and it's fields) which can have unlimited values.
frikovc