I created a select option that gives the user the choice of either:
1) - Add to Cart and continue shopping. Here the customer will add the product to the cart and will be authentically directed to the store.
2) - Add to cart and finalize your purchases. Here the customer will add the product to the cart and will be automatically redirected to the Checkout page.
But the both button redirects me on the store. And when i put "position="replace", i have an error. Can you tell where is the problem here and how can i correct my main.py to redirect the second button in Checkout page.Thank you.
So, this is my work in Odoo 8 :
I tried to create a file xml like this :
<xpath expr="//a[#id='add_to_cart']" position="after">
<div class="custom-select" style="width:200px;">
<select>
<option value="0">Add to cart and:</option>
<option value="#" id="add_to_cart" class="btn btn-primary btn-lg mt8 js_check_product a-submit" >Continue Shoping</option>
<option value="/shop/checkout" id="add_to_cart" class="btn btn-primary btn-lg mt8 js_check_product a-submit">Finish Shoping</option>
</select>
</div>
</xpath>
This is my main.py in the folder controllers :
# -*- coding: utf-8 -*-
import werkzeug
from openerp import http
from openerp.http import request
class website_sale(http.Controller):
#http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True)
def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
cr, uid, context = request.cr, request.uid, request.context
request.website.sale_get_order(force_create=1)._cart_update(product_id=int(product_id), add_qty=float(add_qty), set_qty=float(set_qty))
return request.redirect("/shop")
Can you correct me please? I think my problem is with main.py...
Related
Below is a small part of my data insert form.
My problem is;
The first form object is for the name of the Class room. The field is required and I wanna validate it at server side . In normal it works for sure. But since the next form object is an dropdown menu which get filled from a table of my database, the validation doesn't work. When i post it with empty class room field I get a error.
Normaly it is expected that the server side validation work and stop the posting action right ?
But it doesn't.
What do I miss here ? Thank you.
PS: The teacher field in DB is nullable and when i type something in the class room textbox the form works w/o any problem.
...
...
<div class="col-8 form-floating p-2">
<input type="text" asp-for="AddClassRoom.Class" class="form-control" />
<label asp-for="AddClassRoom.Class"></label>
<span asp-validation-for="AddClassRoom.Class" class="text-danger"></span>
</div>
<div class="col-8 form-floating p-2">
<select class="form-select" asp-for="AddClassRoom.Teacher" asp-items="#(new SelectList(Model.ApplicationUser.OrderBy(x => x.NameSurname).ToList(),"Id","NameSurname"))">
<option value="">select...</option>
</select>
<label asp-for="AddClassRoom.Teacher"></label>
<span asp-validation-for="AddClassRoom.Teacher" class="text-danger"></span>
</div>
...
...
With reference to you comment:
Error is; null parameter(source). Well this is ok, i know it. But there must be a simple way to validate an insert form who has an Database driven content dropdown menu. Post and don't get null after server side validation.
It seems that the dropdown values are not populated after posting the form. Since you have the dropdown values are coming from DB, you need to get its items again from DB after posting the form, so the razor page can fill it again.
More support can be provided if you share your backend code.
[Sample]
Here is a basic sample depending on your code;
<select class="form-select" asp-for="AddClassRoom.Teacher" asp-items="#(new SelectList(Model.ApplicationUser.OrderBy(x => x.NameSurname).ToList(),"Id","NameSurname"))">
<option value="">select...</option>
</select>
Backend:
public ActionResult OnGet() {
// ...
ApplicationUsers = GetApplicationUsersFromDb();
Return Page();
}
public ActionResult OnPost() {
// ...
ApplicationUsers = GetApplicationUsersFromDb();
Return Page();
}
I have a mediawiki multi language site (on sub domains) and I am trying to set up a start page similar to wikipedia, where a user can enter a search term, and then select their language from a select list.
I have no idea where to start, not much experience building forms, So with this question I am at least looking for clues and directions to go.
My idea is a simple search form, and depending on which language was selected, when a user submits, it goes to the url (related to the select list), and appends the searched term.
A simple form to get you started (the form allows you to input an URL and select a language)
function myFunction() {
// get input form values
var url = document.getElementById("iUrl").value;
var langEl = document.getElementById("iLang");
var iLang = langEl[langEl.selectedIndex].value;
console.log("URL = ", url);
console.log("Lang = ", iLang);
window.open(url + "&lr=" + iLang);
}
<form id="form" action="javascript:myFunction();">
<input size="35" type="text" id="iUrl" name="text" value="https://www.google.com/search?as_q=" />
<br>
<select name="language" id="iLang">
<option value="lang_en">EN</option>
<option value="lang_es">ES</option>
</select>
<input type="submit" name="submit" value="Submit" />
</form>
I am getting the following error when trying to run a geb test as a part of a Maven build in Eclipse:
Scenario: Perform login Time elapsed: 0.009 sec <<< FAILURE!
geb.error.RequiredPageContentNotPresent: The required page content 'userName - SimplePageContent (owner: LoginPage, args: [], value: null)' is not present
The only pattern to the error seems to be that it is thrown every time I try to use the geb selector to select/find some page content, but using the selector should work out-of-the-box, right?
I am using the following tools and libraries:
Eclipse Mars Java EE ID (version: 4.5.1)
geb (version 0.12.2)
Selenium (version 2.48.2)
Groovy (version 2.4.5)
Cucumber (version 1.2.4)
Here is my .feature file:
Feature: Login
Scenario: Perform login
Given the user is at the login page
When the user enters <some_uid> and <some_pwd>
Then the user should be logged in
Here is my steps definition:
package stepdefs
import pages.LoginPage
import static cucumber.api.groovy.EN.*
Given(~"the user is at the login page") { ->
to LoginPage
assert at(LoginPage)
}
When(~"the user enters (.*) (.*)") { user, password ->
at LoginPage
page.doLogin(user,password)
}
Then(~"the user should be logged in"){ ->
assert at(LoginResultPage)
}
Here is my page definition:
package pages
import geb.Page
class LoginPage extends Page {
static url = "/TSADG_BORGER/loginpin.do"
static at = { title == "TastSelv Borger" }
static content = {
loginForm { $($/form/$,id:"mainForm") }
userName { loginForm.find("input",id:"pnr") }
pass { loginForm.find("input",id:"tastselvKode") }
buttonLogin { loginForm.find("input",id:"bt1") }
}
def doLogin(user, password) {
userName = user
pass = password
buttonLogin.click()
}
}
Here is the HTML for the form:
<form id="mainForm" action="/TSADG_BORGER/loginpin.do" role="form" method="post" autocomplete="off">
<input type="hidden" name="dispatch" value="Valider">
<div class="row skts-centered-padding">
<div class="col-sm-12">
<h1>Log på med TastSelv-kode</h1>
</div>
<div class="col-sm-6">
<div class="skts-process-form-section skts-required ">
<p><label for="pnr">Cpr-nummer</label></p>
<div>
<input id="pnr" type="text" value="" class="form-control skts-required-val" name="pnr" size="16" maxlength="14" data-validation-event="blur" data-show-type="string" data-show-facets="pattern" data-show-facet-values="/(^\d{10}$)|(^\d{6}\-\d{4}$)/" aria-required="true" aria-invalid="false" aria-describedby="pnrError " autocomplete="off">
</div>
</div>
<div class="skts-process-form-section skts-required">
<p><label for="tastselvKode">TastSelv-kode</label></p>
<div>
<input id="tastselvKode" type="password" value="" class="form-control skts-required-val" name="tastselvKode" size="16" maxlength="16" data-show-type="string" data-show-facets="pattern" data-show-facet-values="/^[^]{7,16}$/" data-validation-event="blur" aria-required="true" aria-invalid="false" aria-describedby="tastSelvKodeError " autocomplete="off">
</div>
</div>
<br>
<p>
<input type="submit" id="bt1" class="btn btn-primary skts-validate" value="Fortsæt" autocomplete="off">
</p>
</div>
</div>
</form>
Any help and input is appreciated.
I would rearrange your content section a bit:
static content = {
loginForm { $("form#mainForm"") }
userName { $("input#pnr") }
pass { $("input#tastselvKode") }
buttonLogin { $("input#bt1") }
}
Use jQuery selectors in Geb! They are very handy. Note that if you use unique ids $("#mainForm"") will have the same effect as $("form#mainForm""). First version is easier, second is more expressive ;)
More info: http://www.w3schools.com/jquery/jquery_ref_selectors.asp
And: http://www.gebish.org/manual/current/#the-jquery-ish-navigator-api
The problem has been resolved.
I was so convinced that it had to be a problem with the selectors, so it took me a while to get my head out of the sand and take a step back. When I did that, I realised that the URL in the "LoginPage" class actually did a redirect to another page, which I was not expecting. The page I was redirected to did obviously not contain any of the objects I was looking for in my contents section. So, when the error message stated that "The required page content...is not present", then that was absolutely correct.
Really silly mistake on my part...
I'm a beginner in the AngularJs and MongoDb world (i started learning today!!)
Actually i'm trying to do something very basic : Display a list of record, with an add button and a edit link with each record.
I'm using this lib https://github.com/pkozlowski-opensource/angularjs-mongolab to connect to mongoweb.
Actually my data is displayed, when i try to add a record it works, but the problem is when i try to display the edit form!
Here is my index.html file, in which i display the data with a form to add a record and with the edit links :
<div ng-controller="AppCtrl">
<ul>
<li ng-repeat="team in teams">
{{team.name}}
{{team.description}}
edit
</li>
</ul>
<form ng-submit="addTeam()">
<input type="text" ng-model="team.name" size="30" placeholder="add new team here">
<input type="text" ng-model="team.description" size="30" placeholder="add new team here">
<input class="btn-primary" type="submit" value="add">
</form>
</div>
And here is my edit.html code, which displays an edit form :
<div ng-controller="EditCtrl">
<form ng-submit="editTeam()">
<input type="text" name="name" ng-model="team.name" size="30" placeholder="edit team here">
<input type="text" name="description" ng-model="team.description" size="30" placeholder="edit team here">
<input class="btn-primary" type="submit" value="validate edit">
</form>
</div>
And finally my js code:
var app = angular.module('app', ['mongolabResource']);
app.constant('API_KEY', '____________________________');
app.constant('DB_NAME', 'groups');
app.factory('Teams', function ($mongolabResource) {
return $mongolabResource('teams');
});
app.controller('AppCtrl', function ($scope, Teams) {
$scope.teams = Teams.query();
$scope.addTeam = function() {
varteam = {
name: $scope.team.name,
description: $scope.team.description
};
$scope.teams.push(varteam);
Teams.save($scope.team);
$scope.team.name = '';
$scope.team.description = '';
};
});
app.controller('EditCtrl', function ($scope, Teams) {
//????????
});
My AppCtrl works perfecty, it displays the data w add records perfectly.
Now i want to add the js code for the edit, but i don't even know form where to start ? how do i a get the id parameter in the url ? how do i tell the view to fill out the form fields from the values from the database ? And finally how do i update the databse.
I know that i asked a lot of question but i'm really lost! thank you
There are of course many possible solutions.
One solution is to use angularjs routing. See http://docs.angularjs.org/tutorial/step_07 for a tutorial.
Basically replace your ul list with something like:
<ul>
<li ng-repeat="team in teams">
{{team.name}}
{{team.description}}
edit
</li>
</ul>
Then you can create a route that responde to your url:
yourApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/teams', {
templateUrl: 'partials/team-list.html',
controller: 'TeamListCtrl'
}).
when('/teams/:teamId', {
templateUrl: 'partials/team-detail.html',
controller: 'TeamDetailCtrl'
}).
otherwise({
redirectTo: '/teams'
});
}]);
In this way from the detail controller (that will replace your EditCtrl) you can access the id parameter using: $routeParams.teamId
Anyway I suggest to study well all the tutorials for a better overview.
My policyInfoAction redirects my form to clientInfoAction. It stores the empty field errors and then validates the fields in the session variables and redirects it to the client-info page if it contains errors.
It works fine. But the problem is the next time I hit the /client-info page in a new tab it shows the form values in the fields. I have to hit the refresh page to clear it out. I do not want it to display cached data when I open the link in a new tab. What should I do?
public function clientInfoAction(){
//If there are some errors and some valid fields, display the valid fields
$client=$this->session->client;
$state=$this->session->state;
unset($this->session->client, $this->session->state); // delete from the
// assign the values to the view
$this->view->client = $client;
$this->view->state = $state;
}
Here is my view:
<form action ="/pdp/policy-info/" method='post'">
<label for="client_name">Client Name: </label>
<input type="text" name="client_name" id="client_name">
<?php if (!empty($this->client_error)) echo "<font size='2' color ='#C11B17'>".$this->client_error."</font>"; ?>
<br><br>
<label for="state">State: </label>
<select name="state" id='state'>
<option id='state' value="" selected="selected"></option>