I have an array:
[
0 => 'translate.label1',
1 => 'translate.label2',
2 => 'translate.label1'
]
which I specify as a choices param for field creation.
Now, is it possible to sort these options by translated labels? For example, label1 translated value is zero, label2 - something, label3 - abracadabra. Of course, I expect select options to be:
abracadabra
something
zero
I thought to use this approach: https://stackoverflow.com/a/21586886/2324004
But doesn't it involve second translator digest inside view? Any ideas? I'd rather to use something more flexible because my form is based on non-fixed selects count and it would have executed something recursive...
You have to do it in js after data will be uploaded.
Check this topic:
Javascript to sort contents of select element
Due to fact the translation occurs inside Twig view, the only solution (right now I'm aware) is to prepare translated and sorted list during form build process by injecting manually TranslatorInterface service.
Unfortunately, without overriding widget's template, translation occurs second time, against already translated labels.
Related
Right or wrong: In Cypress, its impossible to read a value on page X, then keep this value and compare it to a value on page Y.
I can read a value from the page and log it:
cy.get('[data-e2e-selector=whatever]').then(elm => cy.log('Value from page X : ' + elm))
or, for instance, the number of elements with similar or partially matchin selectors:
cy.get('[data-e2e-selector=^whatever]').then(elm => cy.log('Number of elements like this on page X: ' + elm.length))
Hoever, I cannot create a variable of this, because of the asynchronous way Cypress runs. Right? Any value created to just be blank.
Nor can I pass the value read to a method, which in turn compares it to the value on the next page:
compareToValueOnNextPage(cy.get('[data-e2e-selector=^whatever]').then(elm => elm.length));
compareToValueOnNextPage(value: number) { // NB: Not sure if it's a number or string yet...
cy.get('[data-e2e-selector=^whateverNextPage]').then(elm => elm.length).should('have.length', 4)
}
Basically, if I want to compare values, the either have to be on the same page, or they need to be hard-coded. This is a huge limitation when actually end-to-end testing some applications. Very often, a value is created on page X, based on input which should in many cases ba random, thus creating a dynamic value in the test. Then, on page Y, that same value is fetch (from the backend) or shown in some other way, in a Summary etc. And, naturally, I want to compare the value shown on page X to the one shown on page Y/Summary. But this is not possible, due to the very unit-testing thinking that seems to be the foundation for Cypress.
Or am I missing something here? Are there ways around this that aren't ugly/smelly? I think it's possible to store the value on page X in a file, then read that file on page Y. However, Cypress seems to only have one option when reading the file, and that's reading the whole file and looking for a match. So that file would be a mess. Or I'd need several files.
I realize this is kind of trying to impose non-functional ways on a quite functional and asynchroeous technology. However, if it's not possible to "keep" a value and use it later, it's very limiting when it comes to end-to-end testing (even though it's not when the testing is unit-based on frontend components).
UPDATE:
As per Kerrry's suggestion in the answer below:
cy.get('[data-e2e-selector=dellan-accordion]')
.then(elm => cy.wrap(elm.length).as("myVariableName"));
-GO TO NEXT PAGE-
cy.get('[data-e2e-selector=betalingsplan-dellan]')
.then(elm => elm.length)
.should('have.length', myVariableName)
This yeilds "expected 4 to have property 'length'.
This means, obviously, that I cannot get the length of the length.
So I replace 'have.length' with 'eq':
cy.get('[data-e2e-selector=betalingsplan-dellan]')
.then(elm => elm.length)
.should('have.length', myVariableName)
And I get the following error:
expected 4 to equal 0
So, it seems that the first variable - myVariable - is gone after the first cy.get().
If I do everything inside one get (have another get inside that, where I go to the next page AND get the count of the elements), then it works. But the way Kerry shows it, it would be much more flexible. But, alas, the above error.
As jonrsharpe mentioned in the comments, please read the Cypress document on variables and aliases thoroughly. This is a core concept of Cypress, and it will give you a solid understanding of how to implement variables and carry the values between test steps.
The reader's digest example of what you how you can achieve is this:
cy.get('[data-e2e-selector=^whatever]')
.then(elm => cy.wrap(elm.length).as("myVariableName"));
What this is doing is cy.wrap will yield the value from elm.length in a Cypress command chain, which then allows you to assign it to an alias "myVariableName".
In your following test step where you want to compare the value on a separate page, you would then access the alias' value in one of two ways:
Using this.
cy.get('[data-e2e-selector=^whateverNextPage]')
.then(elm => elm.length)
.should('have.length', this.myVariableName)
OR
via cy.get()
cy.get("#myVariableName").then(function(variableValue){
cy.get('[data-e2e-selector=^whateverNextPage]')
.then(elm => elm.length)
.should('have.length', variableValue)
})
Using Domino Designer 8.5. If I have a form with a radio button field, is it possible to disable that field in LotusScript, possibly in the Postopen even of the form?
The only way I can, so far, see of achieving this is by using the Input Enabled formula of the field itself, but I am struggling to understand when this is triggered... if I try to put a #StatusBar or #Prompt formula call in there as well then there is never any notification of Input Enabled being triggered.
If Input Enabled is the way to achieve this, not LotusScript, then is there a way I can have a) a formula that sets the Input Enabled condition plus b) a way of getting some visual output, either to the Status Bar or a Message Box, to either just indicate the formula has been triggered or - even better - to let me know the value of some variable I'd like to check?
The Input Enabled Formula is triggered on every refresh of the document (F9, Save, NotesUIDocument.Refresh, etc.), it can not contain any code "interacting" with the user.
But you could do something like this:
Create a Field "InputEnabled"
The best way to have a "controlling" field is to make it "Computed for Display". That way it is not stored in the document. As a formula you simply enter #ThisValue, then it does not change its value by itself and can be set using LotusScript. If you want to have an "initial" value, then the formula would be: #If( #ThisValue = "" ; "YES" ; #ThisValue )
In the "Input enabled" Formula of your other field write the code:
InputEnabled = "YES"
Fill the "InputEnabled"- Field using a LotusScript (NotesDocument.ReplaceItemValue( "InputInabled", "YES" ), or using a Formula directly in the field.
Like that you can easily "see" what the conditions are (in the field InputEnabled) and change it using formula or script.
Old school way to Disabling the radio button field:
You will have to use the **Hide paragraph if formula is true". Define a field: MyButEnabled accorting to which you enable (show) or disable (hide) the field. for UI convience display a complementary line that only display the value of your radio button (you can also use a computed radio button but it's not very pretty).
In the post open set the appropriated value for the field MyButEnabled. Dont forget to call uidoc.RefreshHideFormulas method.
The notes input enabled way: (see also: http://www-01.ibm.com/support/docview.wss?uid=swg21173862)
the notes input enabled formula is (for example)
#if(MyButEnabled="Y" ; 1 ; 0)
When you form is openned, the formula is computed, if the result is 0 the field won't be editable, 1 will allow field to be edited.
If you change the value of MyButEnabled, then you need to make a UIdocument.refresh in order to change to be reflected in the UI.
I am generating a list of objects in a option tag using ruby rails .eg
%optgroup
-for #people in c do
%option(value: cac,)
how do i specify a default for the option tag? like a place holder which says please select person, and also how do set it from a cookie or previous selected country.
thanks
Something like this should work(not sure what objects you are working with so the attribute names may need to be changed):
%optgroup
-for #people in c do
-if c.id == default.id
%option{value: c.value, selected: true}
-else
%option{value: c.value}
But the helper that #Iceman linked you allows you to do this in a much simpler way. (http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/grouped_options_for_select)
I'm working on a website that uses Domain Access and for a view I expose a filter that lists all domains. I want to list only some domains but not all. I know that it is posible to do with the filter configuration, but if I limit the options this way there is a problem with ajax which changes all the options text to "1", and in any case I want to know how to do it, with either hook form alter or with themes, but preferably using some hook from a module.
In general I'm trying to figure out how to remove some of the options for an exposed filter, I managed to do it using JQuery, but I'd like to do it with php, thanks!
It should be fairly straight forward using hook_form_FORM_ID_alter as you suggest. First inspect the <form> element of the filter form (using Firebug or similar) and get it's ID attribute. The form's ID in Drupal will be that string but with all '-' characters replaced with '_' (so 'form-exposed-filter-form' would become 'form_exposed_filter_form').
The thing to remember is that the submit handler for the form will probably be expecting the elements you're trying to remove to be there, so you'll probably get unexpected results if you just yank them out of there.
The way round it is to change the type of the elements to value instead (so they're available to the submit function in $form_state['values']), and choose a default value for each. Something like this:
// Replace 'FILTER_FORM_ID' with the form's ID
function mymodule_form_FILTER_FORM_ID_alter(&$form, &$form_state, $form_id) {
$form['some_existing_element'] = array(
'#type' => 'value',
'#value' => $default_value_for_filter
);
}
In my multilanguage Drupal 6 website I need to make my CCK field default values translatable, i.e.
Hello - in the English version
Bonjour - in the French one
I cannot find this text with Translation Table, neither are these values in variable table so that I can use multilingual variables.
Do You know how to have different default values in different languages?
When you define the CCK field, you can enter a PHP code snippet to override the default value of the field.
Enter the following there :
return array(0 => array('value' => t('Hello')));
Now access a node add page with this CCK field from a non-English version so that it gets added to translatable strings.
Now you're able to translate it using the "Translate interface" menu (it might take a visit to the "create" page of your cck type first though). It doesn't require any extra modules in fact, just basic D6 (and it probably works in D5 and D7 as well).
This method is a bit of a hack. Im not sure I would deploy this without really considering the consequences. For a simple usecase it MIGHT be ok.
Create a custom module, lets say def_translate. To def_translate.module, add a function
function def_translate_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if($node->type == "sometype"
&& $op == "load"
&& $node->field_some_cck_field_type[0]['value'] == "your default value")
{
$node->field_some_cck_field_type[0]['value'] =
t($node->field_some_cck_field_type[0]['value']);
}
}
Ok - so what is this doing?
When a node is loaded, hook_nodeapi gets called, with $op set to "load". This gives us an opportunity to do manipulate the node before it is rendered. Before we do anything we check
Is this the right type of node?
Is our op = "load"?
Is the value our default value?
What we then do is pass the existing default value through the t() function. This will make the default string available to i18n translation table, and you can then use the normal way of translating strings.
*DISCLAIMER*
I have not tested this myself in production. Im not entirely sure what the effects will be. You probably want to think this through before implementing it, and you probably want to put some features in to look up the default values from the DB incase they are changed in the CCK UI.
Hope this helps - or possibly shakes a hint of a solution to your problem!