Skip to Content Skip to Menu

🕒 Save Time and Effort with CB Editor Assistant: Effortlessly create and refine content in Joomla 3, 4, & 5.
🎁 Limited Offer: Enjoy a 5-day FREE trial and save up to 30% afterward!

Set a non-editable field if another field has a specific value

  • AchLive
  • AchLive
  • OFFLINE
  • Posts: 253
  • Thanks: 14
  • Karma: 3
7 years 10 months ago - 7 years 10 months ago #292007 by AchLive
Hi, I need a way to make a non-editable field only if "Campo_A" is equal to "Active". I do not want the field "Read Only" always.

So I created two fields:
Campo_A
Type: Radio Button
Value 1: Active
Value 2: Not Active
Required: No

Field_B
Type: Text Field
Required: Yes
layout value settings for edit profile:
[Cb: if Campo_A = "Active"] [Field_B] [cb: else] [value] [/ cb: else] [/ cb: if]

When you go into edit profile, if "Campo_A" not equal to "Active" then I display the "Field_B" editable, however, if "Campo_A" equal to "Active" I see the value of "Field_B" (not editable).
Up to this point works well, the problem arises when I try to save the profile with "Campo_A" = "Active"
In fact in the position of "Campo_A" equal to "Active" I get the error: "Field_B" is required.
Where am I doing wrong?
I think I understand that with the code [cb: if Campo_A = "Active"] [Field_B] [cb: else] [value] [/ cb: else] [/ cb: if] displays the correct value but when I try to save He does not know what to write in the field because it has lost its value.
Let me know how I can get the result I'm looking for
Thanks for the support
Last edit: 7 years 10 months ago by AchLive.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48709
  • Thanks: 8319
  • Karma: 1447
7 years 10 months ago #292034 by krileon
The layout parameters are strictly visual. They will not block the save behavior of a field so in theory a user could add the HTML back in manually and cause a change. You should be using CB Conditional to condition the field away in profile edit then use the layout to condition the display in profile view.

In regards to your IF substitution usage you're adding a lot of whitespace that our documentation does not state to add. It is strict as it's regexp so that whitespace will result in it failing. See the below substitution tutorial for further substitution usage information. Several IF substitution examples can be found at the bottom.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18353-using-substitutions-throughout-cb


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • AchLive
  • AchLive
  • OFFLINE
  • Posts: 253
  • Thanks: 14
  • Karma: 3
7 years 10 months ago #292039 by AchLive
Hi, thanks for the reply.
With Cb Conditional I can see or do not see a field on the basis of a condition. I, however, I always need to see it but not make it editable only if the Campo_A = Active.
Maybe I did not understand,

You should be using CB Conditional to condition the field away in profile edit then use the layout to condition the display in profile view.

you can write an example using my example of data written on it?
Thank you

Please Log in or Create an account to join the conversation.

  • AchLive
  • AchLive
  • OFFLINE
  • Posts: 253
  • Thanks: 14
  • Karma: 3
7 years 10 months ago #292048 by AchLive

The layout parameters are strictly visual.

Please try to use in the layout parameters for edit profiles and check that the value of the field before stored in the DB will be deleted.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48709
  • Thanks: 8319
  • Karma: 1447
7 years 10 months ago #292053 by krileon
If you hide the edit output without conditioning the store behavior it'll be the same as saving with empty or null, which results in empty value storing in database. As explained above the layout is entirely visual. You need to use CB Conditional to condition away the edit output. There is no way to condition it and it still be visible at the same time in profile edit. It can be conditioned away in profile edit, but not conditioned away in profile view however which is where you should use the layout parameters to adjust its display. See the below videos to get started with CB Conditional.

www.youtube.com/playlist?list=PLp0puRITgC7PxD6MvmDwNNIi2HNcYxs7u

Your alternative is to use the edit display layout and ensure the edit input is hidden, but still there using CSS. Example as follows.

Code:
[cb:if FIELD_NAME="test"]PASS<div class="hidden">[value]</div>[/cb:if] [cb:if FIELD_NAME!="test"][value][/cb:if]

This however is not secure. Anyone can right click and inspect element, modify the input value, and submit the form to change the value as there is no PHP checks as again layouts are entirely visual. CB Conditional however is a secure means to condition fields.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • AchLive
  • AchLive
  • OFFLINE
  • Posts: 253
  • Thanks: 14
  • Karma: 3
7 years 10 months ago #292059 by AchLive
This is what you need me.

Code:
[cb:if FIELD_NAME="test"]PASS<div class="hidden">[value]</div>[/cb:if] [cb:if FIELD_NAME!="test"][value][/cb:if]

With the Conditional, since I have reset active on settings CB Conditional, the fields would not be visible, but also lose the stored data.
Instead I just want that you can not change the data but which must remain stored on DB.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum