I'm trying to check if a checkbox is checked but, I suppose that as it is disabled, it always returns false. It's disabled because I only use it to show the option is set to the user (I modify it via Ajax). How can I check the real value? Nothing works.
<?php
dd(isset($_POST['bolMensual']));
dd(!empty($_POST['bolMensual']));
dd($request->has('bolMensual'));
if ($request->has('bolMensual')) {
$bolMensual = $request->input('bolMensual');
if ($this->validateDate($request->input('datFecha'), 'Y-m')) {
$datMesAplica = DateTime::createFromFormat('Y-m', $request->input('datFecha'));
dd($datMesAplica);
} else {
return back()->withInput()->with('error', 'Fecha incorrecta');
}
}
Thanks in advance.
Related
I am looking for the condition in cypress to verify and click locator is present or not.
If element is present go to condition and click on the element else leave and continue with the execution. Below code i have tried,
cy.get(".paginationPanel.ng-star-inserted").then(($test)=> {
if($test.text().includes('Show:')){
//do something
}else{
}
})
Unfortunately, I am unable to success. Can anyone please help me.
That code works, what is wrong?
What do you want to click? The "Show" dropdown would be
cy.get(".paginationPanel").then(($panel) => {
if($panel.text().includes('Show:')) {
cy.contains('label', 'Show').prev().click() // click the Show dropdown
} else {
}
})
I need a way to easily trigger a click() event only if an element exist on page.
the fact that the element (confirm modal dialog) itself exist is not an issue for my test, but this can stop next steps. so I want to click OK only if the dialog is shown.
I tried something like this, but it didn't work:
cy.get('body').find("button[data-cy=sometag]").then(items => {
if(items.length) {
cy.get('button[data-cy=sometag]').click();
}
});
If you want to test that the modal exists but don't want to fail the test if it doesn't, use a jQuery selector.
const found = Cypress.$('button[data-cy=sometag]').length
Modals are likely to animate on opening, so you you will need to repeat the check a few times, which you can do in a function
function clearModal(selector, timeout = 1000, attempts = 0)
if (attempts > (timeout / 100)) {
return; // modal never opened
}
if (!Cypress.$(selector).length) { // not there yet, try again
cy.wait(100)
clearModal(selector, timeout, ++attempts)
else {
Cypress.$(selector).click() // modal is up, now close it
}
}
clearModal('button[data-cy=sometag]')
If you use the find like this cy.get('body').find("button[data-cy=sometag]") this will fail always whenever the element is not present. Instead you can use the find command inside the If condition and check its length.
cy.get('body').then($body => {
if ($body.find("button[data-cy=sometag]").length > 0) {
cy.get('button[data-cy=sometag]').click();
} else {
//Do something
}
})
Instead of body, you can also use the parent element of the element in question, which you know for sure is visible and present on the page every time.
I'm having trouble checking out with a virtual product. The checkout works properly with simple products.
The error I get when i check the console is:
(index):620 Uncaught TypeError: Cannot read property 'checked' of null
at beforeBillSave ((index):620)
at HTMLButtonElement.onclick ((index):569)
The code is:
function beforeBillSave() {
var selectedCity = false;
var action = CITIES_ACTION;
var selectCountry = $('billing:country_id').value;
var stateId = $('billing:region_id').value;
if (document.getElementById('billing:use_for_shipping_yes').checked) {
getAjaxReqestShip(action, selectCountry, stateId, normalImputShip,selectedCity)
} else {
$('shipping:city').replace(normalImputShip);
}
billing.save()
}
The problem seems to be that there are no radio buttons of 'Ship to this address' and 'ship to different address' present when checking out with a virtual product.
I tried to look for this code everywhere but failed to find it.
Issue is that there isn't element exists with the given ID. You can wrap this code in this IF condition.
if(document.getElementById('billing:use_for_shipping_yes').length){
// your IF condition code
}
Ok so it was pretty stupid of me to forget that I could just enable the template path hints and find the file which has the code.
I'm using Laravel and I have a dropdown which fills its options from the database on load page and another text field.
Then on the submit I validate the text field to avoid empty entries, the validation is based on the request validator from Laravel. The validation is made correctly.
The problem is that when the validation is completed (it doesn't submit because i keep the text field empty) it returns to the page, but the dropdown remains selected with the last selection by the user, but in the back(sourcecode), its selected the original value that was loaded originally.
I want that the selectedIndex is the one original from the load page, not the last one selected. I tried with javascript but I had no luck change in it since it's already as the selectedIndex, but to the user, it still showing the other option. If I refresh manually it still showing the selected one incorrectly, I need to enter the URL manually so it shows correctly.
What could be a good approach to solve this "visual" issue?
Here is the controller code
public function update($user_id,GuardarBancoRequest $request)
{
$cuenta = user::whereId($user_id)->first();
$cuenta->nombrecompleto = Input::get('completo');
$temp = Input::get('tipo');
$cuenta->tipocuenta = Input::get('tipo');
$temp1 = Input::get('banco');
if ($temp == "1") {
$cuenta->cuentaclabe = Input::get('clabehidden');
$cuenta->cuentatarjeta = Input::get('cuentahidden');
} else {
$cuenta->cuentatarjeta = Input::get('cuentahidden');
$cuenta->cuentaclabe = Input::get('clabehidden');
}
if ( $temp1 == "10") {
$cuenta->otrobanco = Input::get('otro');
$cuenta->banco = "10";
} else {
$cuenta->banco = Input::get('banco');
$cuenta->save();
}
return Redirect::route('bancos.show',array(Auth::user()->id));
}
The dropdown that I'm referring is the [tipo] one
It's hard to presume without getting a chance to look at your code, but it sounds like when you do a redirect after validation you have something like
return redirect()->back()->withInput(); which causes fields to be prepopulated with the values entered earlier on the page. Remove withInput() portion in your controller if you have this.
Otherwise please mind posting your code in addition to your question, that would be helpful. (the controller part with the redirection and the view where you have the dropdown)
I am using static FBML but I am having trouble debugging a form validation problem. I get the dialog which to me seems like it should return false, but the form submits anyway. I am using Firebug and I see a brief message in Red that I have no chance to read. I appreciate the help :-)
var txt ='Enter Zipcode';
//...
function setError(){
var obj=document.getElementById('mapsearch');
obj.setValue(txt);
obj.setStyle('color', '#FF0000');
}
function valform(){
var obj=document.getElementById('mapsearch');
var val = obj.getValue();
if(val!='' && !isNaN(val) && val.length>2 ){
return true;
} else {
setError();
(new Dialog()).showMessage('Zip Required', 'Please enter your zip code.');
return false;
}
}
//...
Try the "Persist" button if the Firebug/javascript error message in Firebug disappears too quickly. This way all messages are kept between page loads until you click "Clear".