Best way to prevent data being overwritten

Best way to prevent data being overwritten

crush123crush123 Posts: 417Questions: 126Answers: 18
edited February 2015 in Editor

I have 2 datatables/editor pages, one in admin, the other in user area, pointing to the same json source.

On the admin page, i want an additional option in editor to set a boolean field value to 1 or 0, but on the user page, i want this data field to be read only

In my editor instance on the user page i am not displaying this field, (only in the datatable).

On editing the user page, the boolean value is always set to 0 and overwrites the database value.

Do I need to create a second instance of the json source and use ->set( Field::SET_NONE ) for the user page, or am i just doing it wrong ?

--also, in a related question, is there a way i can display a checkbox in my datatable, but read-only, so it cannot be clicked ?

I have several checkboxes displayed, (using the permanent inline checkboxes example)
http://www.datatables.net/blog/2014-09-09

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Editor and its server-side libraries will only write to the fields that it is instructed to do so. So I guess the question is, are you sending that value from the user page? Certainly there would be nothing wrong with using the set() method - you could do something like:

    ->set( $_SESSION['admin'] ? Field::SET_BOTH : Field::SET_NONE )
    

    (depending on how you store user information of course).

    --also, in a related question, is there a way i can display a checkbox in my datatable, but read-only, so it cannot be clicked ?

    Add the disabled attribute to the checkbox.

    Allan

  • crush123crush123 Posts: 417Questions: 126Answers: 18
    edited February 2015

    Thanks Allan,

    Can't work out what was being sent from the user page to overwrite the value, so I took a different approach, keeping the field in the editor, but keeping it hidden, so the value was retained. - seems to work ok.

    Also like your solution, will keep that logged

    Also cheers for the checkbox thing. I was playing around with adding class attributes, not thinking I just need to add input type="checkbox" disabled="disabled"

This discussion has been closed.