Public Ticket #3418083

Read-only textboxes

Closed
Comments
6 Tickets 6
Min Tran started the conversation 3 years ago on July 19, 2023 at 7:02am

Hi, I want to set input textboxes in New Subaccount to read-only. This means users cannot enter or paste text to these textboxes.

Can you please provide the custom CSS code to do this.

Thank you.

2,762
KingsPlugins replied 3 years ago on July 19, 2023 at 3:20pm

Hi Min, 

Just to make sure I understand this correctly, can you please clarify, should it be for both "new subaccount" and "edit subaccount"?


So is the idea that only the website admin should be able to set the information there?


Please let me know and I'll work on a way to set that to read-only.

Kind regards,

Stefan

6 Tickets 6
Min Tran replied 3 years ago on July 19, 2023 at 11:20pm

Hi Stefan,

I need them to be read-only on both "new subaccount" and "edit subaccount" pages.

Due to our business process, Last Name and First Name of subaccounts are only edited by WordPress admin.

So, CSS or code snippets would be suitable.

Thanks.

2,762
KingsPlugins replied 3 years ago on July 21, 2023 at 7:29pm

Thank you for clarifying,

I believe you can solve this by adding this PHP code snippet to your site:

add_action('wp_head', function(){
    ?>
    <script>
        jQuery(document).ready(function(){
            jQuery('input[name="b2bking_subaccounts_new_account_name"], input[name="b2bking_subaccounts_new_account_last_name"]').prop('readonly', true);
            jQuery('input[name="b2bking_subaccounts_new_account_name"], input[name="b2bking_subaccounts_new_account_last_name"]').attr('placeholder', 'This field can only be edited by the site admin');
            jQuery('input[name="b2bking_subaccounts_new_account_name"], input[name="b2bking_subaccounts_new_account_last_name"]').css('background', '#d2d2d2');
        });
    </script>
    <?php
});

A PHP snippet can be added to functions.php, or by following our guide here: https://b2bkingplugin.com/docs/how-to-add-a-snippet-php-or-js/

It should result in those 2 fields being read-only:

5838317797.png

The code also changes the text and the background color of the fields.

Kind regards,

Stefan

Sign In