Retrieving UserPicker Widget emnail string using onValueChanged - google-app-maker

I am new to app maker. When working with the User Picker widget which allows for a drop down selection of valid email address within a domain, logging the newValue under onValueChanged would output [object Object] instead of the email address selected. Am I doing something wrong?

That is because in the property editor, you are selecting the option valueIsRecord. According to the official documentation:
valueIsRecord boolean Whether the value property is a primitive value or record.
If this checkbox is selected, the newValue is set to the the user object record hence you are getting [object Object]; However, if the checkbox is not selected the value will be primitive, therefore it will give you an email address.

Related

How to trigger initial_place_name event in Workflow Component for state machine

I created an entity with not null status property. Workflow Component is configured to use that property for marking store. The initial_marking option is set to draft.
Entity always has got some status, so that property can't be null. This is why when I want to create new entity I have to provide it's initial state - in this case draft.
According to doc
If you initialize the marking by calling $workflow->getMarking($object);, then the workflow.[workflow_name].entered.[initial_place_name] event will be called with the default context (Workflow::DEFAULT_INITIAL_CONTEXT).
However that event isn't triggered, because entity status property was already set to draft during creation.
class Training
{
public function __construct(
private string $title,
private string $status,
) {}
}
$training = new Training('title', 'draft');
$trainingStatusStateMachine->getMarking($training); // <- here `workflow.entered.draft` event should be triggered
How can I trigger that initial event in such case?
What is the purpose of initial_marking option if I have to keep my entity valid upon creation?
added clarification
The point is that workflow.entered.draft event isn't triggered because $training status was set during creation. This is why Workflow Component ignores triggering the event because subject is already in the workflow.
To fix the situation I should not set the status (leave it null) and allow the Workflow to set initial place name. But I do not want to do it, because I do not want to allow my entity to be invalid.
Another solution is to create "fake" initial status for example init and add transition from init to draft. Such case is fine but then initial_marking option make no sense.

enable validation on objects that are embedded

I need help to know how to validate a property that is embedded to an object but which is not required. I mean that I want to validate this embedded property only if its value is not null.
For example, in the documentation of Symfony 3, you have 2 entities Author and Address. http://symfony.com/doc/current/reference/constraints/Valid.html
To validate address, you must add #Assert\Valid() to address property in Author entity. I'm OK with that. If the property address is absolutely required, it's good.
But how about the case that the property address is not required at all, each time I submit the form without fill the address fields, I will get errors because the #assert/Valid() on address property in Author entity.
How I can deal with that ?
Thanks

Can you set an Internal parameter using the Report Viewer control?

Is it possible to set an internal parameter value using the Report Viewer control?
rv.ServerReport.SetParameters(new ReportParameter[] { new ReportParameter("Username", User.Identity.Name) });
{"The report parameter 'Username' is read-only and cannot be modified.
(rsReadOnlyReportParameter)"}
I've heard that you can only set an internal parameter using the Report Viewer...but it seems an internal parameter is just that...internal. To be clear, an internal parameter on the server side is one where both Hide and Prompt are not checked on the parameter definition. If Hide is checked (hidden parameter), the parameter can still be passed in via a query string or on a subscription.
MSDN - Creating Report Parameters and Setting Report Parameter Properties:
Hidden and Internal Parameters
You can set options that control parameter visibility in the published
report. Setting the Hidden and Internal options provides different
levels of visibility. You can hide the parameter on the parameter
input area of the published report, yet set values for it on a report
URL or in a subscription definition. If you set a parameter to
Internal, it is not exposed in any way except in the report
definition. An internal parameter must have a default value, which can
be null if the Allow null value option has been selected.
Update, after a bit of testing:
This is actually a confusing definition. The parameter is exposed in Report Viewer and the value can be easily overridden in the report properties and the properties of a linked report.
You are still unable to set the value of an internal parameter from the URL or from the drill-down action from another report. It is visible when you create the action but when you try to drill-down you get the error: The report parameter 'name' is read-only and cannot be modified. I wouldn't imagine you will be able to modify the value from code either, but I haven't tested that.
I had the same issue. I was sending to SSRS by URL some parameters. I needed to validate/edit the parameter if contains certain character. something like that:
=IIF(Parameters!Par1.Value Like "*]","[Table1].[Field1].&[" + Parameters!Par1.Value + "]]","[Table1].[Field1].&[" + Parameters!Par1.Value + "]")
In the Parameter Definitions. in "Select Parameter Visibility" I had marked the option: "Internal". I changed to "Hidden" and it allowed me to edit the parameter. why? no clues. but now is working

How to access z3c.form widget settings from browser view

Given following widget based on z3c.form https://github.com/collective/Products.UserAndGroupSelectionWidget/blob/z3cform-widget/src/Products/UserAndGroupSelectionWidget/z3cform/widget.py
I would like in some browserview to access its settings and corresponding field. Since Widget does not know the schema and field upfront, I'm interested in what information do I need to get widget and field. Currently I have available the fieldname and context, which seemed to be enough for archtypes https://github.com/collective/Products.UserAndGroupSelectionWidget/blob/z3cform-widget/src/Products/UserAndGroupSelectionWidget/browser.py#L60
EDIT: To simplify the question, I would like to access a field that is defined in some z3c form and its widget. I could not find other way except passing request and context to form init and then accessing the field. Is there a multiadapter?
The idea is to have a z3c.form widget that people hook into whatever field which does an ajax call. That ajax request needs to pass parameters and response will lookup where widget was used and with what settings. The question is, how to lookup the z3c.form field and which information is needed to do so?
Getting the Field
If you can get the schema, you can get the field.
For a dexterity content type, if you know the field name and the type's portal_type, you can get the schema from the type's Factory Type Information (FTI).
So, if we know portal_type and field_name:
from zope.component import getUtility
from plone.dexterity.interfaces import IDexterityFTI
fti = getUtility(IDexterityFTI, name=portal_type)
schema = fti.lookupSchema()
field = schema.get(field_name)
Getting the Widget
From the z3c.form documentation: http://packages.python.org/z3c.form/widget.html
The widget is a multiadapter, so if you have the field, you can get it like so:
ageWidget = zope.component.getMultiAdapter((field, request),
interfaces.IFieldWidget)
Important: If you have however specified a widget via plone.autoform, then that widget won't be fetched. plone.autoform manually sets a widgetFactory on the z3c.form.field.Field object (which is not the same as the zope.schema Field!). The best way to get the widget then, is what you have already done, by manually calling initiating a FieldWidget.
So for example if you want the UserAndGroupSelectionWidget:
widget = FieldWidget(field, UserAndGroupSelectionWidget(field, request))
P.S Since I'm also in the collective and use the picker widget, I've updated the code for you ;)

Why input elements don't render the value passed in ASP.Net MVC?

This post asks this question but doesn't really give an answer, so I thought I would ask the question differently.
I have a page that renders a hidden value from the model:
<%=Html.Hidden("myName", model.myValue) %>
Since I am passing a value in the value parameter, you would think it would output that value, but it doesn't.
The code for rendering input fields has the following:
string attemptedValue = (string)htmlHelper.GetModelStateValue(name, typeof(string));
tagBuilder.MergeAttribute("value", attemptedValue ?? ((useViewData) ? htmlHelper.EvalString(name) : valueParameter), isExplicitValue);
Basically, if the ModelState (which contains posted values) contains a value for the "name" passed, it will use that value instead of your passed value to the helper method. In my case, I updated the model and my updated value wasn't outputted.
If I pass a value to a method, I expect that value to be rendered.
Am I missing something in this design or is it just wrong?
This is by design. Here is the intended flow:
The user requests a certain URI.
Your controller builds out a model.
The view is rendered. The ModelState dictionary should be empty at this point, so the value you pass to Html.Hidden will be rendered. However, the feature in question is more directly related to user input, so consider the case of Html.TextBox("someName", Model.SomeValue)
Now imagine the user enters some invalid data. If you have a client-side validation, this would be caught before the POST, but let's pretend you don't, or that the user has somehow circumvented it.
In this case, the action which handles the POST will return a ViewResult, causing the view from step 3 to be re-rendered. However, the user will see the value they input (so they can fix it) instead of the value from your model object. The idea here is that the data the user entered possibly cannot be represented as a value in Model.SomeValue, due to type safety. If Model.SomeValuewas of type integer, for example, and the user entered "ABC", the only way to re-render the user's data is to put it somewhere else. And that "somewhere else" is ModelState.
Re-displaying the user's invalid data allows the user to fix the data they entered and re-post the form.

Resources