1

I was looking for some fieldtype that is supported by Grid to act as a "is_default" flag in my Grid rows. This field would only allow 1 row checked.

Looking at this page, I thought that MX Lone Star would do the job. But after trying it out and doing some investigative work, it is only compatible as a fieldtype in 2.7+ but not as a fieldtype that is supported by Grid.

Are there any alternatives out there?

2
+25

There isn't a Celltype for Grid that does this yet as far as I know. But you can easily make this happen using a bit of jQuery. You can add the jQuery directly into the custom field's instructions or use CP CSS & JS.

This will ensure that only one checkbox remains checked across a particular column in your Grid field (tested with EE 2.7.1):

<script type="text/javascript">
    $(function() {
        var checkboxes = $('#field_id_28 td[data-column-id=2] input');
        $('#field_id_28 td[data-column-id=2] input').change(function(event) {
            checkboxes.prop('checked', false);
            $(this).prop('checked', true);
        });
    });
</script>

Just be sure to set field_id-x and data-column-id-x in the selector to match your field and column.

demo gif

Important note: If you are entering this jQuery snippet in a custom field's Field Instructions make sure it does not use space characters for the indentation. If you copy and paste directly from here it will and they will be encoded to &nbsp; which will cause a JavaScript error.

4
  • Unfortunately, part of the specs is that we assume some of our users won't have Javascript. So a JS only solution won't suffice. Oct 4 '13 at 5:36
  • 1
    If users don't have JavaScript, they won't be able to add rows to the Grid field, or delete them, or sort them... In fact, having JS enabled is required for the CP, as stated in the docs: ellislab.com/expressionengine/user-guide/installation/…
    – Low
    Oct 4 '13 at 11:36
  • We are allowing users to edit some parts of their profile in the frontend using Safecracker Registration. This is one of those information. So that JS requirement is moot since the frontend does not require JS. Oct 7 '13 at 7:14
  • Let us know what you come up with!
    – Alex Kendrick
    Oct 11 '13 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.