Disable fields in the account setting form

Account Settings (name, email, password) can be accessed by users clicking the Account Setting link. This brings up a Knack-default form. The Account Settings form allows users to make changes to their name and email address.

If you do not want them to make changes, you can use the code below.

The Account Settings view is a Knack-default view. No view can be defined for this in the Interface hence the use of the ".any" view selector.

#first, #last are the field names for first name and last name. You can't use the field_xx names in the User Object.

field_253 is the field name for the email address as per the User Object.

// do not allow users to change their name or email address. 
// // #first is the fieldname for the first name, #last is the fieldname for the last name.
// field_253 is the fieldname for the email address. 
$(document).on("knack-view-render.any", function(event, view) {
	$("#first").attr("disabled", "disabled");  
  	$("#last").attr("disabled", "disabled");  
  	$("#field_253").attr("disabled", "disabled"); 
})

Cheers

Hi again Andrzej

OK using your code below works perfectly. Just what I needed. Thanks so much. John

.account-settings {
  display: none;
}

.kn-view.kn-login h2:first-child {
display: none;
}

Hi Andrzej

Being somewhat of a novice, Using this CSS code:

#kn-scene_96 div.account-settings {
    display: none;
}

I need to find my Scene # can you tell me how to "update my environment" as noted above?

Thanks

John

Thanks Andrzej

This is great. Really appreciate the help :)

This is what works for me:

.account-settings {
  display: none;
}

.kn-view.kn-login h2:first-child {
display: none;
}

put it in CSS in Knack.

final effect is like this:


Hi Sam

Can you tell me how to add something to your code that puts a space in between the headers, and maybe even adjust the style of each so that it looks a little prettier?

The 2 headers together like this looks like something is missing!

Good stuff. I've used both suggestions in my apps, thanks !

After some trial and error I found that you can hide this section including the submit button. This method will still allow password change.

NOTE: your kn-scene_# may be different, if so update for your environment.

CSS code below:

#kn-scene_96 div.account-settings {
    display: none;
}

Before

After



This is much better , thanks!

I think what you proposed will disable the name fields on any form, which may not be the desired outcome. Also not sure where you got the field number for email - mine is different. But the following code will specify the name fields based on a class of account settings - this only affects those forms:

$(document).on('knack-view-render.any', function(event, view) {

$(".account-settings #first").attr("disabled", true);

$(".account-settings #last").attr("disabled", true);

});