Update an Optional element to protobuffer - r

I'm using R for coding. I need to add/update an optional field in my protobuffer files. The function "add" works well for repeated fields; but it does not seem to be compatible for optional fields.
example:
A$add("gender", X["gender"]); # Works if A is repeated; but not when it's optional!
Do you know what function I should use for this purpose?
Thanks

try the following
A$set("gender", X["gender"]);

I found the solution!
If "add" does not work, you should try:
A$gender = X["gender"];
Should work!
Thanks

The optional field already exists. You only need to assign a value to it.

Related

#JMS\Exclude only if a property is empty

I am using JMS\Serializer in my project and I want to ignore one property only if the array in it is empty.
I tried something like :
#JMS\Exclude(if="count('$this->required') === 0")
or
#JMS\Exclude(if="empty('required')")
but got a syntax error.
Can anyone help me on this?
thank.
What you need was implemented recently and it is in release-1.7 so you might as well wait for it. It is called #SkipWhenEmpty
#SkipWhenEmpty This annotation can be defined on a property to
indicate that the property should not be serialized if the result will
be "empty".
This is the bug related it.
You need this one:
#JMS\Exclude(if="!object.required")

Clear field and type in DalekJS

I'm relatively new to DalekJS and I've been battling with clearing a field, and then typing. The .type() seems to only add to an existing string in an input box, is there any way to clear the field before typing?
I thought I´d implemented this some time ago, but reading my own source code made it clear to me that this isn't the case.
As long as the clear() method is not implemented, you can use this function as a workaround:
.execute(function () {
document.getElementById('id-of-the-element').value = '';
})
That should do the trick.
better is to use jQuery otherwise you only can select id fields
$('#somedivid > span.some-class.other-class > form > input').val('');
See you
It does work with...
.setValue ('selector', 'value')

Need to make parameter as Read-Only,

In selection-screen, I have one parameter called 'Author' I have called the report using 'Submit' from other report and passed the value to 'Author'. Now I need to make the 'Author' parameter as Read-only. How can I do that?
I used the following code,
LOOP AT SCREEN.
IF SCREEN-NAME = 'author'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
EXIT.
ENDIF.
ENDLOOP.
But it is not working. Can any one help me in resolving this?
Put your code in the at selection-screen output-event.
Disclaimer: This answer does not answer exactly your question, but perhaps it is an easier solution for your need.
If you need only a parameter for SUBMIT you may use
PARAMETERS AUTHOR NO-DISPLAY.
The parameter will not be visible on selection screen, but it can be used via SUBMIT.
This is not a 'read-only' it is a 'don't show' parameter.

Drupal: change view argument

I searched far and wide to find a working solution to this but couldn't find it.
What I want to do is change the argument that is passed to the view because I want for pathauto cleaned taxonomy terms to work as an argument. I have a code that transforms cleaned term back to a original one, but cannot make the view use it.
I saw some people changing it in hook_preprocess_views_view(&$vars) but in my case (Views 2.11) has a argument in $vars instanced so many times that it's not the way.
Can anyone please help me change this argument?
There may be a better way but you could use views_embed_view() and set the arguments yourself
I have two ideas, either to add some custom php code to the view's argument's phpcode section that does something like this
$args[0] = 1;
return $args;
or try to use the function
hook_views_pre_view(&$view, &$display_id, &$args) {
// modify $args value here
}
didn't test them so don't know which will work.
I think hook_views_pre_view might help you do just that.

Custom formatter

I need to create a new custom formatter(using the module custom formatter) to replace some template code. So, for some fields, When I add a new custom formatter(field type: text) I need to print the title and the body. I tried to use $node->title but it doesn't work...
How can I do this? Probably using elements? And if yes...how?
Thanks in advance,
Regards,
Michele
Field formatters relate to the field that they are used for, it it's impossible to answer your question without know what field you are using (and it's contents).
To debug this, you could use the devel module and a bit of code. If you in your formatter write.
dpm(get_defined_vars());
this will give you a pretty printed list of all variables you have available. That should help you inspect and figure out how you get to what you need.
Custom formatters get's passed $element, if you do a dpm of $element (dpm($element) - If you have the Devel module installed) you will see the entire array, and notive that the $node object is passed as $element['#node'].
So with that said, to get to the node title you would use $element['#node']->title.
Please also not that it does say this on the help text of the custom formatters UI.

Resources