Jump to content

Remove Fields from Template - Suggestion for global checkbox


Cybermano
 Share

Recommended Posts

Maybe it's an intentional lack to be sure and to double check the deleting of the fields from a template.

But when developing new sites from older one, for me it's usefull to delete lot of fields quickly.
Some times templates needs to be cleaned from lots of fields, so for me it's bit annoying to check all fields one by one (for many templates).

I wrote few line of js and loaded them in admin side to have a global checkbox to check all the others for fields removal.

Maybe somebody here could consider to implement this feature in the template ui (obviously, in a much more elegant way than mine 😉 )

My code has a very basic behaviour, without the full range of control (just select/unselect all and uncheck when removing one from all checked ones)

$(document).ready(function(){
   
    // Only when selected fields to be removed are more than 1
    if ($('input[id*="Inputfield_remove_fields_"]').length > 1){

    // get fields list to delete and add a global checkbox
    $('li.Inputfield_remove_fields ul.InputfieldCheckboxesStacked').append('<li><div style="margin-top:20px;"><b><label><input type="checkbox" name="select_all" class="uk-checkbox"><span id="select_all_label" class="pw-no-select">Select All</span></label></b></div></li>');

    // some basic logics on checkbox change trigger
    $('input[name="select_all"]').change(function(){
        if ($(this).is(':checked')){
            $('input[id*="Inputfield_remove_fields_"]').prop('checked', true);
            $('span#select_all_label').text('Unselect All');
        } else {
            $('input[id*="Inputfield_remove_fields_"]').prop('checked', false);
            $('span#select_all_label').text('Select All');
        }
    })

    // additional basic logic on field checkboxes uncheck
    $('input[id*="Inputfield_remove_fields_"]').change(function(){
        $('input[name="select_all"]').prop('checked', false);
        $('span#select_all_label').text('Select All');
    });

    }

});


Then this code has to be loaded in admin.php, as usual after the load of JqueryCore (tanks @Soma http://soma.urlich.ch/posts/custom-js-in-processwire-admin/ )
$config->scripts->add($config->urls->templates . "YOUR_PREFERRED_DIRECTORY/YOUR_FILENAME.js"); 

Hope it could be useful or for inspiring.

A little screencast:


 

  • Like 2
Link to comment
Share on other sites

8 minutes ago, bernhard said:

Can't you do a SHIFT+CLICK to select all from the first click until the last click?

Sorry to hijack the thread, but... would you believe that I literally just learned that you can do this with checkboxes? That makes things so much easier. I've always considered this part of the admin pretty cumbersome, having to click all those checkboxes one by one 😄

(Perhaps this view should include a note about this, unless this is something that everyone else already knows about?)

  • Like 2
Link to comment
Share on other sites

Yeah I agree it's quite a hidden feature. Similar to the double-click-delete on files/images... I think there has been some discussion about it some time. Maybe it was a github request, don't know 🙂 But a note would certainly not hurt here 🙂 

  • Like 2
Link to comment
Share on other sites

Thanks everyone for the suggestions.

In fact, if I had known about this "hidden" function, I would never have asked myself how to solve it adding my own custom code ... 🤣

Even if I think the global checkbox is even more immediate.😉

So in case of a next "note" adding, I suggest to consider my option first. 🙂

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...