I declared a new FormControl like this :
senderCity = new FormControl("", [Validators.required ]);
In future I add some value like :
if(legBet){
let splited = legBet.value.split(',');
this[errorLable].setValidators([ Validators.minLength(splited[0]), Validators.maxLength(splited[1]) ]);
}
But seems not works expected. when max, min length not throws error. is it correct way to add or some wrong here?
any one help me?
Related
I'm trying out the Cosmos DB SDK's new Patch/Partial Update-functionality (for .NET)
When adding a new property I use
var patchOperations = new List<PatchOperation>(){
PatchOperation.Add<string>("/FavoriteColor", **null**)
};
await container.PatchItemAsync<T>(
id: myId,
partitionKey: new PartitionKey(myPk),
patchOperations: patchOperations);
The problem is, that it throws at the PatchOperation-Add() if I set second parameter to null (with message "Value cannot be null"). I can set any non-null string and it works well. I just wonder if this isn't supported yet or if I missed something.
Thanks to github user rvdvelden (source), this work around appears to work perfectly:
private JToken NullValue { get { return new JProperty("nullValue", null).Value; } }
Used in this way:
operations.Add(PatchOperation.Set("\customer", value ?? NullValue));
Remove is one alternative if the intent is to remove field/property.
This is not supported with Patch yet,
However, if you want to remove the entire property you need to use Remove Operation
I have just got this error a few days ago. Whenever I try to run
this.store.queryRecord('user', {filter:{username : params.username}});
It shows error: Assertion Failed: Expected the primary data returned by the serializer for a queryRecord response to be a single object but instead it was an array.
What is the problem here?
You backend should return one object not array.
Found a way to avoid this problem. Instead of queryRecord ( which seems to be changed by ember-data developer team ), I use store.query like this:
this.store.query('user', {filter:{username : params.username}}).then(function(user){return user.get('firstObject')});
I encountered similar situation , had 2 routes
this.get('/clients', function() {return {data: [allClientsDataJson]};});
this.get('/clients:id', function() {return {data: [oneClientDataJson]};});
But after using queryRecord i got same error. Thing was that second route was never called and first one was called in both causes. So instead of single result there was array with all results in second call.
After knowing only first one is always called i edited it to :
this.get('/clients', function(db, request) {
if(!Ember.isEmpty(request.queryParams)) { return oneClientDataJson
} else { return allClientsDataJson }
I have a problem on yii model, ive been told to use the generateAttributeLabel() on the model, but i tried to use it on the way i thought it would work but it doesnt. This is my code
public function generateAttributeLabel($variable = file_get_contents('protected\column.txt'))
{
return $variable;
}
public function attributeLabels()
{
return array(
'id' => 'ID',
'parametro_id' => 'Parametro',
);
}
There are some columns that are being generated automatically and i thought to save their names into a file and its saved as example like (index, par, tolt, sircer). Thats why the file_get_contents(), but i get an error:
Parse error: syntax error, unexpected '(', expecting ')'.
so i really dont know and i need this to make checkboxlist with the attributes of each column thats going to be saved as y or n, if someone could tell me how to use this with checkboxlist would be appretiated.
the content file is this
lololo,
for now it has 1 element, but will be adding more each time a column is created
You can't use a function return value as a default value in a function declaration, you will need to set that up in the function itself
public function generateAttributeLabel($variable = null){
if($variable){
$variable = file_get_contents($variable);
}
return $variable;
}
I have a yii application. Data is validated properly. the $model->validate() returns true but data is not being saved. Is there any way that I know about the error. It does nothing. neither prints error nor any warning.
if (isset($_POST['Invoice'])) {
$model->validate();
$model->attributes = $_POST['Invoice'];
if (!$model->validate()) {
die(CVarDumper::dump($model->errors,10,true));
}
if ($model->save()) {
die("Data saved");
$this->redirect(array('view', 'id' => $model->id));
} else {
CVarDumper::dump($model->attributes,10,true);
CVarDumper::dump($model->errors,10,true);
}
}
if you override beforeSave or afterFind method in your model,
public function beforeSave() {
return true; //don't forget this
}
public function afterFind() {
return true; //don't forget this
}
make sure you return true for those function
If save() is returning true and there are no errors as such in your database and queries. Only thing, thats possible is you haven't marked some of the column safe for mass assignment via "$model->attributes".
Make sure the column you are trying to save are marked safe in the "rules" function in your model. You can mark columns safe via adding the following rule in "rules" function in the model.
array ( "column_name1, column_name2 ....." , "safe" )
I've just ran into something similar to this. Everything was validating correctly, and $model->save() was returning true, but no data was saved in the database.
The problem and solution was that I was creating the $model object like so:
$model = ClassName::model();
but you need to create the object like so:
$model = new ClassName;
If you have this problem, you replace this:
$model->save(false)
This solves your problem.
If you use $model->save(); the filters is running that is not good for you.
Fire up some logging and see what going on...
I got the same error when I was using reCaptcha. I just did this and it worked:
$model->scenario = NULL;
Make sure you do this AFTER validation.
I had the same issue, my mistake was with the post name in the controller, where I used $model->save. I had given wrong - if(isset($_POST['postname']))
If I am not wrong, you are doing an AR save() in the $model->save() method. You do not get any error, but the data is not saved as well.
If this is the case you would like to do a:
die(CVarDumper::dump($arObj->errors,10,true));
after the $arObj->save(); call. Most of the time this happens because of the Database rejecting the values provided for insert or update.
Also do not override your model constructor:
function __construct() { } // don't do this
The issue for me was that I had a property for the column name in the ActiveRecord class, so it wasn't saving.
You should not declare properties for column names as I guess the magic methods __get() and __set() are used to save data, I guess by checking if there are column changes when you click the save() method to avoid useless SQL queries. In my case, because the column was a user-declared property, it wasn't in the columns list and therefore changes to it were not detected.
Hope this helps other people
Is it possible to define a method like below to receive $id?
public function action_delete($id){
}
I've defined a route
Route::set('tweet', 'tweet/delete/<id>', array('id' => '\d+'))->defaults(array(
'controller'=>'tweet',
'action'=>'delete'
));
I remember a code snippet something like this few months ago...
Updated: I get the following error message
Missing argument 1 for Controller_Tweet::action_delete()
If your Kohana version < 3.2 then you can use this, however it is highly recommended that you get the id value with $this->request->param('id') -> this is the only way since 3.2 version:
public function action_delete(){
$id = $this->request->param('id');
// Rest of tour code
}
In Kohana 3.2, this doesn't work anymore. You'll have to retrieve the variable through
$id = $this->request->param('id');
See: http://kohanaframework.org/3.2/guide/api/Request#param