I was wondering if it is possible to show or hide a view based on a condition. I now have an ImageView that I only want to show if a file is uploaded. In all other cases I would just like to show something like a textfield with ‘please upload a file’… is this possible?
For now I have solved it by using a UserException… not the nicest way though…
if not params.file_resource:
raise UserException("Please upload a cpt file.")
Thanks for the question, very interesting one.
Currently it isn’t possible to hide views completely, moreover maybe in this case I fear that it would be slightly confusing to the user if a view would suddenly pop up after a certain action.
In this case I would advise something similar to the suggestion you made using the
UserException (which by the way is deprecated as of sdk v13.7.0 and replaced by
UserError). You could also consider basing the
ImageView on a similar conditional statement. So showing a simple image with the plain text “Please upload a cpt file” unless a file has been uploaded. Would that be an acceptable alternative for you?
Either way, I do think the idea of completely hiding views is interesting so I will open an internal issue to have that discussion in. I will keep you posted here if any developments follow from that!
Thanks for the deprecation warning and yes I also thought about creating an empty image or one with a warning / message to show as long as there is no upload but to be really honest I think it would be nicer to have the option to hide fields so I am curious about the discussion.