Page 1 of 1

changing attribute name, not value, with form controls in Author View

Posted: Sat May 07, 2022 1:52 pm
by ttasovac
Hi.

I have a date picker form control like this:

Code: Select all

correspAction date:before {
    font-family: "Platforma Sans", sans-serif;
    content:
        oxy_label(text, "Датум: ", width, 30%)       
        oxy_datePicker(edit, '@when', width, 23%, format, 'yyyy-MM-dd', fontInherit, true, color, inherit);      
}
It works as expected and it enters the date into the `@when` attribute. So far so good.

In TEI, however, we need to use a different attribute for inexact dates, either `@notBefore` or `@notAfter`. So, next to the date picker, I'd like to add an oxy_comobox with the default value `@when`, and two additional values `@notBefore` and `@notAfter`, and then an oxy_action onChange that would replace `@when` with the selected attribute name (`@notBefore` or `@notAfter`) and keep the date picker working with the new attribute.

Is this something that can be done? If not, what's the most elegant way of giving the user this kind of choice without overcrowding the form?

Many thanks in advance.

All best,
Toma

Re: changing attribute name, not value, with form controls in Author View

Posted: Mon May 09, 2022 3:02 pm
by alex_jitianu
Hello,
In theory it sounds feasible. The onChange can execute an XQueryUpdateOperation, for example, to refactor the document. Afterwards, to make the date picker edit a different attribute you can rely on a number of extra selectors:

Code: Select all

correspAction date[notBefore]:before {
    font-family: "Platforma Sans", sans-serif;
    content:
        oxy_label(text, "Датум: ", width, 30%)       
        oxy_datePicker(edit, '@notBefore', width, 23%, format, 'yyyy-MM-dd', fontInherit, true, color, inherit);      
}
correspAction date[notAfter]:before {
    font-family: "Platforma Sans", sans-serif;
    content:
        oxy_label(text, "Датум: ", width, 30%)       
        oxy_datePicker(edit, '@notAfter', width, 23%, format, 'yyyy-MM-dd', fontInherit, true, color, inherit);      
}
Best regards,
Alex

Re: changing attribute name, not value, with form controls in Author View

Posted: Mon May 09, 2022 11:33 pm
by ttasovac
That's very cool, Alex. I see I can also do it with XSLT, which is easier for me.

The one bit that I'm still missing is how to pass the selected value from the combobox to my XSLT script:

Code: Select all

oxy_combobox(        
        edit, "@ana",
        editable, false,
        values, "when, notAfter, notBefore",
        labels, "тачно, пре, после",
        onChange, oxy_action(
          name, 'Refactor Date', 
          description, 'Change the attribute depending on selected value', 
          operation, 'ro.sync.ecss.extensions.commons.operations.XSLTOperation', 
          arg-script, '${pd}/xslt/refactorDate.xsl'
          arg-sourceLocation, '.',
          arg-targetLocation, '.',
          arg-externalParams, 'dateKind=???')
)
What do I need to put there instead of ??? to refer to the selected value?

Many thanks in advance.

All best,
Toma

Re: changing attribute name, not value, with form controls in Author View

Posted: Tue May 10, 2022 9:51 am
by alex_jitianu
Hi Toma,
I think that you can use xpath_eval, like this:

Code: Select all

'dateKind= ${xpath_eval(@ana)}'
. Another option is to use XQueryUpdateOperation which is invoked in the content of the element:

Code: Select all

            onChange, oxy_action(
                name, 'Insert',
                operation, 'XQueryUpdateOperation',
                arg-script, 'insert node <product>{xs:string(@attribute)}</product>
                          as last into .')

Re: changing attribute name, not value, with form controls in Author View

Posted: Tue May 10, 2022 10:28 pm
by ttasovac
Thanks, Alex!