How to set the 'options' of an HTML docfield from a script

Hello all

I’m familiar with setting the Options of an HTML docfield in the WUI as show below

However, how do I set the Options dynamically with coding, either server-side with Python or client-side JS?

Thanks so much.

You might be able do it with a call to set_df_property followed by a field refresh. Under most circumstances, though, I would probably just manipulate the dom directly using JavaScript.


Thanks @peterg , you’re always so helpful :+1:

For the benefit of others reading this, here’s some inspiration:

I used the onload event to call fRenderFields

frappe.ui.form.on('eP Client', {
    onload: function(frm) {

and fRenderFields contains this section of code

frm.set_df_property("fields","options",'<!-- markdown -->\
\n<p>Use the following fields</p>\
\n<div class="row">\
\n  <div class="column">\
\n  <ul>\
\n    <li>appraisee.first_name</li>\
\n    <li>appraisee.last_name</li>\
\n  </ul>\
\n  </div>\
\n  <div class="column">\
\n  <ul>\
\n    <li></li>\
\n    <li>appraisal.appraisee_id</li>\
\n  </ul>\
\n  </div>\

Resulting in

Screenshot from 2022-06-22 12-10-29

As an alternative to an HTML docfield, I’ve also looked at the Read Only docfield. You can set the Read Only docfield’s value (not options) programmatically as for any other docfield’s value.
Note that a Read Only, unlike an HTML, by virtue of it having a value is persisted to the DB. An HTML docfield does not have a value, only options, and is therefore not saved to the DB. Furthermore a Read Only docfield accepts HTML code.

frm.set_value('code', '<!-- markdown --><h4>if x_1 < y/z</h4><br>');