Error handling in embedded_list

edited January 2016 in Share
I'm using embedded_lists extensively to handle related items in a model and I need to check certain conditions before allowing a related item to be deleted. I can put the checks into on_before_delete methods in the related models and use add_error to add a message to the user to inform them why the delete action was not permitted. However, as far as I can see, the error collection does not get displayed to the user as a result of an inline_delete. So, the user's experience is that they attempt to delete something, and it doesn't delete and there's no explanation for it.

Is there a better way you can suggest of handling this?

Thanks

Comments

  • edited 7:52PM
    You could perhaps try overriding the model's embedded_list_items function (which returns a string of the table) and insert the error above it:
    public function get_embedded_list_items($params, $list_cols = array(), $actions = array('edit')) { $table = ''; if (has_errors()) { $table .= display_errors().$table; } $table .= parent::get_embedded_list_items($params, $list_cols, $actions); return $table; }
  • edited 7:52PM
    Hi, Thanks for the quick response. I can see the principle, but I think I'll need to adapt it as I'm using the Model's error object rather than the validator, but by the time this function is reached, the errors seem to have gone out of scope. Not sure whether I should be using 'register_to_global_errors' where I'm doing the check in on_before_delete?
  • edited 7:52PM
    What about using session->set_flashdata?
  • edited 7:52PM
    Yes thanks, that's a good way to go
Sign In or Register to comment.