thesilentman VIP
Total posts: 33
02 Окт 2015 02:52

Hi,

so I have started working with Cobalt for a few hours and I have reached an issue where I have a boolean field, which want to be editable and submitable only by admins, but viewable by registered.

I have set the access fields as follows:

  • View Access - Public
  • Submission Access - Special
  • Edit Access - Special

Expected behavior (for a registered user):
Label is displayed. Boolean buttons are displayed, but set as readonly and not being accepted, even if the form is tampered with.

Actual behavior (for a registered user):
Label is displayed. Boolean buttons are not displayed. Instead the default denial-message is displayed in their place, saying "You cannot edit this field".

From the code at components/com_cobalt/views/form/view.html.php I can see that this is the way it works, but it does seem weird.

Hence the title question...

Последние изменения: 11 Окт 2015


Jeff VIP
Total posts: 745
02 Окт 2015 07:40

thesilentman Expected behavior (for a registered user):

Label is displayed. Boolean buttons are displayed, but set as readonly and not being accepted, even if the form is tampered with.

Why would you want to show a field in a form if they are not allowed to edit it?

I would hide it altogether by hiding the label and replace "You cannot edit this field" with a space. I think it is even possible to enter html in the restriction message field, so in theory you could place some code that mimics a boolean button in read-only state.


thesilentman VIP
Total posts: 33
02 Окт 2015 10:23

Hi Jeff,

thanks for your reply.

Why would you want to show a field in a form if they are not allowed to edit it? I would hide it altogether by hiding the label and replace "You cannot edit this field" with a space.

Because the user needs to see it's state, without being able to edit it... ;) Only the admin has the right to edit this field. No use in hiding it.

BTW, these types of fields are not uncommon in business apps.

I think it is even possible to enter html in the restriction message field, so in theory you could place some code that mimics a boolean button in read-only state.

Thanks for the hint. I might try it out.

I also have thought of different solutions on this, but have to explore first.


Sergey
Total posts: 13,748
02 Окт 2015 13:24

This is how it works. it is not easy to show field in readonly mode. because ther are a lot of fields and is have to be consistent. If in one field I show in readonly mode then all fields have to do the same. but there are very complex field. For example geo. How could i show map and marker with readonly mode. It is possible technicaly but would coumplicate fields very much.

This is why it works like this, you cannot edit field? you do not see field.

As s solution for you if it is simple text field, you can create custom field output template where you can add readonly to the field but make it accessible to everyone.


pepperstreet VIP
Total posts: 3,837
02 Окт 2015 14:10

Jeff it is even possible to enter html in the restriction message field, so in theory you could place some code that mimics a boolean button in read-only state.

Confirmed. HTML markup works.
(but would not help in this particular case, because it should display the current field value/state.)

So, custom field output template is the way to go.


FYI - The missing Bootstrap 2 & 3 Toggles


thesilentman VIP
Total posts: 33
02 Окт 2015 14:24

Sergey This is how it works. it is not easy to show field in readonly mode. because ther are a lot of fields and is have to be consistent. If in one field I show in readonly mode then all fields have to do the same. but there are very complex field. For example geo. How could i show map and marker with readonly mode. It is possible technicaly but would coumplicate fields very much.

This is why it works like this, you cannot edit field? you do not see field.

As s solution for you if it is simple text field, you can create custom field output template where you can add readonly to the field but make it accessible to everyone.

I understand, yes that is doable, but I think this is missing.

I think there could/should be a hook for these cases which could or could not be used by fields, in order to be able to render a "readonly" version of the field, if possible. This would lean more towards the expected behavior.


thesilentman VIP
Total posts: 33
02 Окт 2015 14:26

pepperstreet

Jeff it is even possible to enter html in the restriction message field, so in theory you could place some code that mimics a boolean button in read-only state.

Confirmed. HTML markup works.

(but would not help in this particular case, because it should display the current field value/state.)

So, custom field output template is the way to go.


FYI - The missing Bootstrap 2 & 3 Toggles

Yes, either that or a hook as I proposed in the previous post


thesilentman VIP
Total posts: 33
02 Окт 2015 14:51

@pepperstreet: Oh and many thanks for the info on the missing bootstrap toggles. Will look into those too.


Sergey
Total posts: 13,748
05 Окт 2015 13:11

thesilentman I think there could/should be a hook for these cases which could or could not be used by fields, in order to be able to render a "readonly" version of the field, if possible. This would lean more towards the expected behavior.

Agree, that would be nice. initialy I had this idea to show current value of the field. But during process I discovered that it is very dificult to create universal algorithm for unknown type of field. The only solution that worked at that time, was hide all field.

If you have an idea how to implement it neatly, I am open.


thesilentman VIP
Total posts: 33
05 Окт 2015 13:47

I actually wrote something a few posts earlier in this thread.

I think there could/should be a hook for these cases which could or could not be used by fields, in order to be able to render a "readonly" version of the field, if possible. This would lean more towards the expected behavior.

I think if you implement a function in one of the base clases of the fields, that maybe just outputs the value, the fields' templates could override this function and output their own custom-formatted version of the value.

I haven't given this much thought though, but I think it should be practical like this.


Sergey
Total posts: 13,748
07 Окт 2015 14:31

That make sense and easy to do. We can add parameter to show current value or not. Let me think if it can be done without losing compatibility.


thesilentman VIP
Total posts: 33
08 Окт 2015 17:45

Hi Sergey,
quick question:
is this something that you might do within the next couple of days and release an update for Cobalt, or will it take more time? I ask because I have to deliver the project soon and I need to know if this will be available or I have to do some more custom development on that end.


Sergey
Total posts: 13,748
11 Окт 2015 12:11

Rught now I am pritty much bussy. not sure I'll have time to do that.

Работает на Cobalt