October: RecordFinder should have a "Remove" option

Created on 23 Dec 2015  路  18Comments  路  Source: octobercms/october

Hey!
If I select a record in the recordfinder, then later I can not clean it, but sometimes it is necessary (to set a null value). It would be good to implement the mechanism clean recordfinder.

High Accepted Enhancement

Most helpful comment

whoot whoot, thanks @daftspunk

All 18 comments

as solutions can create a record witdh id 0, and to use it for cleaning)

Good point. For justification, can you provide a real-world example that shows a time where you would need to dissociate a record using record finder?

I agree there should be a remove/clear button :)

1+

+1

Note to maintainer: Handle #1669 as part of this.

edit: Should have been #1199

+1. I've tried adding this myself, but having trouble following the code.

In terms of UI, I might suggest the cleanest option would be to add a button to the bottom of the pop-up list window (i.e. 'Delete', 'Clear', or 'Remove' button next to 'Cancel' button?).

+1

+1

+1

I've written this dirty patch for now; Add to your plugin's javascript. It also watches for pop-up modals and applies to those. (apologies, javascript is not my thing)

(function(){"use strict";
    function initItemLinkRemove(el, index) {
        var $target = this;
        var $input = $('input', $target);
        var $container = $input.closest('.form-group');
        console.log('<<< init item link remover', $input);
        if (!$input.length || $input.attr('data-remove-init') == 'true')
            return;
        $container.append('<button type="button" class="close" style="position:absolute;right:40px;top:32px;background-color:#fff">脳</button>');
        $('.close', $container).click(remoteItemLink);
        $input.attr('data-remove-init', 'true');
    }
    function remoteItemLink(e) {
        var $container = $(this).closest('.form-group');
        var $input = $('input', $container);
        var $control = $('.form-control', $container);
        console.log('<<< removing item link', $input.val());
        $input.val('');
        $control.html('<span class="text-muted">Click the <i class="icon-th-list"></i> button to find a record</span>');
    }
    $('.recordfinder-widget').each(initItemLinkRemove);
    MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
    var observer = new MutationObserver(function(mutations, observer) {
        mutations.forEach(function(mutation) {
            var c = mutation.target.getAttribute("class");
            if (c == 'modal-content') {
                $('.recordfinder-widget').each(initItemLinkRemove);
            }
        });
    });
    observer.observe(document, {
      subtree: true,
      attributes: true
    });
});

Fixed by #2756

whoot whoot, thanks @daftspunk

Wow! This is great! Thank you .. and just when I needed it.

What about adding a new record from within the record finder? Is there a simple yet effective way to accomplish this? Seems strange that it is not already documented.

@WaskiWabit Use the RelationController for this http://octobercms.com/docs/backend/relations

@daftspunk My problem is that I will have tons of records (customers) which is more suited for the RecordFinder. And if a customer doesn't exist, I would like to be able to create one from the record finder instead of leaving my current location and having to go to the customer controller. Is this possible?

@WaskiWabit Yes, try using the RelationController behavior.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sozonovalexey picture sozonovalexey  路  3Comments

jvanremoortere picture jvanremoortere  路  3Comments

dunets picture dunets  路  3Comments

ChVuagniaux picture ChVuagniaux  路  3Comments

mittultechnobrave picture mittultechnobrave  路  3Comments