Breezejs clear multple keys - breeze

We have the following mapping in EF6:
HasRequired(x => x.modulemain).WithMany().HasForeignKey(t => t.moduleid);
HasOptional(t => t.modulerslt).WithMany().HasForeignKey(t => new { t.moduleid, t.trmendrs });
HasOptional(x => x.modulegoal).WithMany().HasForeignKey(t => new { t.moduleid, t.trmgcode });
HasOptional(x => x.modulefase).WithMany().HasForeignKey(t => new { t.moduleid, t.trmfcode });
Breezejs understands this mapping with the combination of the two keys. BUT there is a problem: Whenever the user 'clears (sets its value to NULL)' the modulegoal/modulefase/modulerslt sets the moduleid value to an empty string and the 'second key' as well. The problem is that the first keys is being used in multiple references. So clearing one of the references, mismatches the other (important) references. Is there any way to tell breeze to NOT clear the first key?

Related

Symfony 1.4 order a widgets data

I have a sfWidgetFormDoctrineChoiceMany widget, I was wondering if there was a way to order the data inside it in ascending order
'locations_list' => new sfWidgetFormDoctrineChoiceMany(array('model' => 'Location')),
To set ordering on sfWidgetFormDoctrineChoiceMany (and sfWidgetFormDoctrineChoice too) you should provide a order_by option. Like this:
// ...
'locations_list' => new sfWidgetFormDoctrineChoiceMany(array(
'model' => 'Location',
'order_by' => array('Name', 'asc'), // <--- replace 'Name' with your column name in camel-case format
)),
// ...
When I need to get a quick reference on widget supported options, I always go to it's source. Usually they have a nice documentation right in PHP comments. Check this link to sfWidgetFormDoctrineChoice source:
https://github.com/nationalfield/symfony/blob/a2d4442dfeb26355e89360f6e725c1f19c3a1ee0/lib/plugins/sfDoctrinePlugin/lib/widget/sfWidgetFormDoctrineChoice.class.php#L33

Mvc CheckBoxListFor named argument specifications error

Im using Mvc CheckBoxListFor extension. Argument specification seems quite right to me as it's shown on the demos but it still gives me named argument specifications must appear after all fixed arguments have been specified error. And i also want to specify id attribute.
Thanks for any help in advance.
#Html.CheckBoxListFor(model => model.Categories.PostedCategories.CategoryIds,
model => model.Categories.AvailableCategories,
entity => entity.CategoryId,
entity => entity.Name,
model => model.Categories.SelectedCategories,
position: Position.Horizontal,
x => new { #class = "actcheckbox" }) // here is the line that occurs that error.
#Html.ValidationMessage("catSelectionError")
As the error message suggests, you have a named argument which is followed by a fixed argument - position: Position.Horizontal. It would seem you need to do the following:
#Html.CheckBoxListFor(model => model.Categories.PostedCategories.CategoryIds,
model => model.Categories.AvailableCategories,
entity => entity.CategoryId,
entity => entity.Name,
model => model.Categories.SelectedCategories,
Position.Horizontal, // NB: No argument name
x => new { #class = "actcheckbox", id = "myid" }) // Add id here

Zend validate interprets "disabled" input fields as empty

I again ran into a problem I just canĀ“t seem to comprehend.
I have a form element like so:
$this->add(array(
'type' => 'datetime',
'name' => 'modifiedTime',
'options' => array(
'label' => 'Modified Time',
),
'attributes' => array(
'disabled' => 'disable',
),
));
This one does get filled correctly trough my entity(I am using doctrine) like so:
/**
* #ORM\Column(type="datetime", nullable=true, name="modified_time")
*
* #Form\Exclude()
*/
protected $modifiedTime;
public function getModifiedTime(){
return $this->modifiedTime;
}
public function populate($data)
{
$this->modifiedTime = date_create($data['modifiedTime']);
}
This works completly fine as long as the "disabled" attribute is not set. But as soon as it is I get a validation error claiming "Value is required and can't be empty" eventhou the value is set in the input.
any Ideas?
The disabled attribute does exactly what it states. It disables the html-form-element. This means, that when you sent the form back to your service/controller, that form field will not be posted.
Now my assumption is that you don't want users to edit some data that's displayed in an EditForm? In this case, don't use disabled, better choose readonly for displaying purpose.
On Server-Side, simply ignore what the user is posting. As when it's readonly, the data will still be sent and can be modified by the user using browser-dev-tools ;)

How do I use the 'When' method in ASP.NET MVC Fluent Validation?

I am trying to develop a fluent valiation rule where if my TitleId FK property is null, then the TitleOther text field becomes mandatory. I have tried several combinations and orders of fluent expressions, all to no avail.
This is what I have so far, if someone can please help me get this one When part correct, I would be most grateful, and a little more educated.
context.RulesFor(p => p.TitleId).Required(p => p.Message("Title is required."));
context.RulesFor(p => p.TitleOther)
.Required(p => p.Message("Please provide your other title."))
.Length(0, 50, c => c.Message("Other title may not exceed 50 characters")
.When(p => context.RulesFor(p => p.TitleId). *[what here?]*
I haven't used FluentValidation much, but from what I understand from the docs you would need to do
.When(p => p.TitleId == null)
instead of .When(p => context.RulesFor(p => p.TitleId). *[what here?]*
I have used When in my project in Fluent Validation. I have used for 1 condition that is compare password as like below:
RuleFor(u => u.Password).NotEmpty().WithMessage("Please Enter Password"); // Normal checked for non empty
When(u => !string.IsNullOrEmpty(u.Password) && !string.IsNullOrEmpty(u.ComfirmPassword), () =>
{
RuleFor(u => u.ComfirmPassword).Equal(x => x.Password).WithMessage("Password does not match");
}); // For compare password
Hope it helps you.
Thanks.

Symfony sfWidgetFormInputFile deleted my file

Sorry for the many questions but I'm new to Symfony. I made a form and all it working well. I a few fields for pictures (Picture1, Picture2, Picture3, etc). I used te sfWidgetFormInputFile and all is working well with that as well. It uploads the file where it needs to and it gives it a unique name.
The problem I'm having is that those fields are set in mySQL to have a default value of "no-pic.png" so that if the user doesn't upload a picture, it will still have something to show in the post. But every time someone uploads a picture, it deletes my no-pic.png file and the posts without a picture show with a blank square. I'm thinking it's because it's set to "delete previous image" before uploading the new one to reduce excess unused pictures on the server.
I'm wondering if there's a way to have it check to see if the value is "no-pic.png" before deleting it from the folder. In case it helps, this is the code I'm using in the form.class file.
$this->widgetSchema['picture1'] = new sfWidgetFormInputFile(array('label' => 'Pictures', ));
$this->validatorSchema['picture1'] = new sfValidatorFile(array('required' => false, 'path' => sfConfig::get('sf_upload_dir').'/car', 'mime_types' => 'web_images', ));
$this->widgetSchema['picture1'] = new sfWidgetFormInputFileEditable(array(
'label' => 'Pictures',
'file_src' => '/uploads/car/'.$this->getObject()->getPicture1(),
'is_image' => true,
'edit_mode' => !$this->isNew(),
'template' => '<div>%file%<br />%input%<br />%delete%%delete_label%</div>',
));
$this->validatorSchema['picture_delete'] = new sfValidatorPass();
Just for reference here is the code I used.
$this->setWidget('logo_image', new sfWidgetFormInputFileEditable(array(
'file_src' => 'uploads/logos/'.$this->getObject()->getFilename(),
'edit_mode' => !$this->isNew()
)));
$validatorOptions = array(
'max_size' => 1024*1024*10,
'path' => sfConfig::get('sf_upload_dir').'/logos',
'mime_type_guessers' => array(),
'required' => false
);
if ($this->isNew())
{
$validatorOptions['required'] = true;
}
$this->setValidator('logo_image', new sfValidatorFile($validatorOptions));
$this->setValidator('logo_image_delete', new sfValidatorString(array('required' => false)));
I found a workaround. I had the page check to see if it was set to no-pic.png and then it displays a no-pic.png in another location. That way when it goes to upload a picture, it won't delete it. :) Thanks for your help though.

Resources