[['captcha'], 'captcha', 'required'],
If I do this, it says:
Setting unknown property: yii\captcha\CaptchaValidator::0
But it works fine if I do following:
['captcha', 'captcha'],
['captcha', 'required'],
What do you think the problem is? Why can't I combine the rules?
Because in Yii, rules are represented as an array like this:
['field1', 'validator1', 'valProp1'=>'valProp1Value', 'valProp2'=>'valProp2Value', ...]
so this array applies only to 1 validator but multiple fields and valProp1, valProp2 are inbuilt Validator Class properties. Some example would be:
['field1', 'email','skipOnEmpty'=>true]
which setups yii\validators\EmailValidator on a field1 field and setups skipOnEmpty property of email validator to true
In order to combine rules, you need to to write in format where every rule is separate per validator, something like this:
['captcha','captcha'],
['captcha','required']
Related
I comment, and looked here and I can not find the solution, my problem is the following:
in my html template in angular, I need to pass a series of data to the metadata property of a button, I can't get the correct way to successfully concatenate the variable that contains the value.
this should be the html element:
<mati-button clientId="clientId" flowId="flowId" color="green"metadata='{"user_id":"1234778","email":"som#som.com"}'/>
I tried several ways but I can't insert the respective values....
example:
<mati-button metadata='{"userID": "{{user.id}}" }'></mati-button>
unsuccessfully...
Assuming mati-button is an Angular component with metadata as Input(), you are probably looking for
<mati-button
[clientId]="clientId"
[flowId]="flowId"
[color]="green"
[metadata]="{ userId: '1234778', email: 'som#som.com'}"
></mati-button>
See the guide on property binding to learn more:
To bind to an element's property, enclose it in square brackets, [], which identifies the property as a target property. [...] The brackets, [], cause Angular to evaluate the right-hand side of the assignment as a dynamic expression. Without the brackets, Angular treats the right-hand side as a string literal and sets the property to that static value.
By "dynamic expression" they mean JS-expressions, i.e., a public variable available through the component's TypeScript, a boolean expression, an array, or, like in your case, a JS-object that you can construct inline.
You can try doing this
<mati-button metadata="{'userID': user.id }"></mati-button>
metadata='{" userID ": {{user.id}}}'
in the end I got it. Apparently I don't know why, but the third-party script hides that parameter and it couldn't be debugged in the console, but it does receive them without any problem! Thanks everyone for your help!
I am faced with the question of how I should set up my Angular components with regard to inputs.
The first variant would be to create an input variable for each given value. This means that you would have to enter each variable individually when calling it:
The second variant would be to pack all the required values in a model and only include this model. So in the end only one input:
Now I don't know which of the two variants is better suited for a large app with many components.
Is there one i should prefer from these two or are there more i dont know yet?
It depends upon your component info what info you are passing for example if the component is a shared button in which expected inputs could be button name, class, status etc.
In that scenario instead of passing all inputs separately you could go with one object lets say props which contains button properties.
export interface IButtonProps {
text: string;
class: string;
disabled?: boolean;
}
buttonData: IButtonProps;
this.buttonData = {
...this.buttonData,
text: 'Submit',
class: 'primary',
disabled: false
}
In template instead of passing individual input pass an object of buttonData
<my-button [props]="buttonData"></my-button>
Your example doesn't really explain itself too well but here goes:
If your input's are all of the same type and used for the same thing, theres nothing wrong with putting all of them in an array and passing them to the child.
Instead of:
[input]="'string1'" [input2]="'string2'" you could do [input]="['string1', 'string2']"
However consider this:
[iconClass]="'my-icon-class'" [buttonClass]="'my-button-class'"
Each of the inputs do something completely different, so putting them inside of an array would be very bad practice.
What you could also do is put all inputs in an object, for example:
input = { iconClass: 'my-icon-class', buttonClass: 'my-button-class' };
[input]="input"
You should only be using this, if the inputs are somehow related or/and do the same thing / modify the same element in the child.
When I sign an XML document I get:
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="xmldsig-f62dafae-6983-4b97-9b52-3f24c6960c43">
....
<ds:SignatureValue Id="xmldsig-f62dafae-6983-4b97-9b52-3f24c6960c43-sigvalue">
VpJzFiW62NK2ytlUkAYF....
</ds:SignatureValue>
....
</ds:Signature>
Is it possible to get ds:SignatureValue without the Id attribute?
It isn't possible to control the presence/value of that (and other) IDs, since it's hard-coded on the signer class. These IDs may be needed by some qualifying properties, hence being added.
How do I add a filter attribute to <iron-data-table? (Please post a plunk demo.)
I forked this plunk. Then I tried to add a filter by adding the following line:
<iron-data-table
...
filter="['item.user.name.first.length', '< 5']">
Which broke the plunk. Here is the new (now broken) plunk.
The documentation here describes the filter attribute as follows:
filter An array containing path/filter value pairs that are used to filter the items.
But it lacks an example of how to use it.
How do I add a filter attribute to <iron-data-table? (Please post a plunk demo.)
This isn't a very well documented feature:
Normally, you would go about using filter-by and filter-value properties in <data-table-column> elements, but you can also access the filter property directly.
When it comes to filtering items data source, there is only "contains" kind of filtering available. So, you pretty much can't do filtering based on string length like in your Plnkr with those. For more custom filtering functionality, you need to go using a function dataSource where you can do anything you want using the filters provided as arguments for the data source function.
Anyways, in case you want still to access filter directly and for example provide a default filtering value, you need to set the value to be an array of objects, which have a path and filter property:
this.filter = [{path: 'user.name.first', filter: 'donna'}];
Here's an example: http://plnkr.co/edit/KIefwLNHeinkOgERWOvZ?p=preview
Is it possible to have a single database value (say, a post/zip code) split across two html input tags (the first 4 digits in the first, and the last 3 in the second).
I am currently using the helper method of displaying the form, but as far as I'm aware, I could use 'raw' html to achieve the same thing (and if this is the case, I would not mind at all changing my view file to have the raw html). So is there a way that I can use raw html, have two input tags for postcode, and somehow combine their values in the controller?
So this is my model file:
db.define_table(
'user_address',
Field('street_address', 'string', requires=IS_NOT_EMPTY()),
Field('city', 'string', requires=IS_NOT_EMPTY()),
Field('country', 'string', requires=IS_NOT_EMPTY()),
Field('postcode', 'string', requires=IS_LENGTH(7)),
)
This is my controller:
def new():
form = SQLFORM(db.user_address)
if form.accepts(request,session):
response.flash = "form accepted"
return dict(form = form)
And this is my view:
<section>
<h2>Register</h2>
{{=form.custom.begin}}
{{=form.custom.widget.street_address}}
<br>
{{=form.custom.widget.city}}
<br>
{{=form.custom.widget.post_code}}
<br>
{{=form.custom.widget.country}}
<br><br>
{{=form.custom.submit}}
{{=form.custom.end}}
</section>
If you want to use the built-in form processing functionality, breaking up the field into two inputs could get complicated. A simpler approach might be to include two additional fields in the database table and making the combined "postcode" field a computed field:
db.define_table('user_address',
Field('street_address', 'string', requires=IS_NOT_EMPTY()),
Field('city', 'string', requires=IS_NOT_EMPTY()),
Field('country', 'string', requires=IS_NOT_EMPTY()),
Field('postcode1', label='Postal Code', requires=IS_LENGTH(4)),
Field('postcode2', requires=IS_LENGTH(3)),
Field('postcode', compute=lambda r: r.postcode1 + r.postcode2,
readable=False, writable=False)
You would still need to use the custom form code so you can keep the postcode1 and postcode2 inputs inline and suppress the label for postcode2.
The default table definition above will always show the postcode1 and postcode2 fields and hide the postcode field (i.e., in forms and the grid). If you are simply displaying a record (e.g., using the grid feature), you can instead set the readable and writable attributes of postcode1 and postcode2 to False and the postcode attributes to True.
One other option would be to define a custom widget for the "postcode" field. The widget should include the two visible input elements you want to display in the form as well as a hidden input element with the name "postcode". You would then need some Javascript (which could be included in the widget code or simply loaded separately) to automatically concatenate the values in the two visible inputs and put the result in the hidden input. The widget code would also have take the existing value in the postcode field and split it into the two visible widgets (this will be necessary for update forms, which display existing values in all of the form inputs).