Forum Bugs

Selected option not being displayed

jascroftleigh
Please can you help me to understand an unexpected behaviour in Prince XML. I have narrowed this down to a very simple example HTML file:

<select>
  <option>Please select</option>
  <option selected>Yes</option>
  <option>No</option>
</select>


I have attached the output I generated from Prince XML 8.1r3 and wkhtmltopdf 0.9.9 as PDF files.

My expectation is that the PDF rendering would match the Chromium and Firefox browsers which is to show the selected "Yes" value. This is what wkhtmltopdf does. Prince XML seems to show the "Please select" value i.e. always the first option.
  1. example-prince.pdf9.2 kB
  2. example-wk.pdf6.0 kB
mikeday
Yes, this is a limitation of the way Prince handles select and option elements at the moment. It can be fixed in this case by applying a couple of additional CSS rules:
option[selected] { display: table-row }
option:not([selected]) { display: none }

However, this will show no options at all if none of them have the selected attribute. Fixing this may require a small piece of JavaScript, or a more complex set of CSS rules.
jascroftleigh
Those selectors work well for me. We have applied some additional styles to make the pull-down menu look nicer but basically this workaround is good.

Thanks for your rapid response.