Vue.js if statement with two variables - vue.js

I need to check if the current user is the author of the question to allow him to see/use the delete question button.
But with my implementation I can´t see the button at all:
<form #submit.prevent="deleteQuestion(question.id)">
<input type="submit" v-if="this.currentUser === question.author" value="Löschen"/>
</form>
I get question.author with a JSON request , currentUser is set during the login.
Thanks for taking the time,
Fierl.

this.currentUser and question.author are not the same objects, even though they might contain the same data. This is why the comparison fails.
Your user objects probably have an id property (or some other primary key). Compare against that instead.
<input type="submit" v-if="this.currentUser.id === question.author.id" value="Löschen"/>

Related

Assertion error when IDs are same for different behaviors of an element

I am dabbling with a Role based access situation and am sort of stuck on the assertion.
For the Full Access the field is like so
<input class="clickable_input clickable_timeholder ui-autocomplete-input ui-widget ui-widget-content ui-corner-left hidden" data-old-value="12:00 am" type="text" value="12:00 am" name="program_constraint[event_window_constraints_attributes][0][local_start_time]" id="program_constraint_event_window_constraints_attributes_0_local_start_time" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
For the Readonly access the field is like so
<input class="hidden clickable_input clickable_timeholder" data-old-value="12:00 am" type="text" value="12:00 am" name="program_constraint[event_window_constraints_attributes][0][local_start_time]" id="program_constraint_event_window_constraints_attributes_0_local_start_time"></input>
I would like to work with only 1 selector that is the one with the full access and then check for exists or not to pass or fail the case.
I end up with the below assertion error primarily because both the conditions use the same ID and the only difference is in their class name. I have not found a good example yet to handle this. Being still a week old into working w/TestCafe, I understand the DOM model perfectly fine, I can't seem to quite incorporate this into a page model effectively and keep hitting a wall.
expected true to be falsy
This is my Selector definition in the page model:
this.eventWindowStartTime = Selector("#program_constraint_event_window_constraints_attributes_0_local_start_time")
my Test code for the assertion
await t.expect(programOptionsConstraintsPage.eventWindowStartTime.exists).notOk()
You can use the filter method to find only an element with a particular css class.
For example:
Selector('#input_id').filter('.ui-widget')

How auto refresh component when data updated from api, without page refresh

I’m trying to make component like a LIKE count,
so,
i have a object is name (LIST) which i get from api, in my LIST object have property total_like which default value is 0, when i click to like button i make post request to api and in api my total_like value rising to 1 and 2 and etc.
in my view i’m displaying the like count with {{item.total_like}} everything work well to this point.
problem is item.total_like value updating only when i refresh the page, but i want to show new value of this property without refreshing page.
how can i figure out with it ?
regards
Maybe you can use the event modifiers to prevent page reloading, examples are...
<button type="submit" v-on:click.prevent="addLike" >
<button type="submit" v-on:submit.prevent="addLike">
or if you want to use the shorthand
<button type="submit" #click.prevent="addLike" >
<button type="submit" #submit.prevent="addLike">
Hope this helps.

How in Sinatra would I check that the term the user has input into a form already exists in your database?

Making a budget app while learning to use Ruby/Sinatra/SQL. Part of it involves letting the user add new vendors that they can assign transactions to. My add transaction and add vendor functions both work, but one thing I'd like to do is be able to throw up an error if the vendor that the user is trying to add - eg 'Amazon' is already in the database, before returning to my index of vendors.
The closest that I've come to getting something working is making the name column of the vendor table UNIQUE. But if I enter a name that's already in existence in the field, I get the "PG::UniqueViolation" error.
Is there a way to tell Sinatra that you don't want this error to flag up, you just want to redirect back to the index of vendors without the repeated value.
My working submission form currently looks like:
<div id="new-transaction">
<form action="/vendors/create" method="POST">
<label for="name">New vendor name:</label>
<input type="text" name="name" id="vendorName" />
<input type="submit" value="Add new vendor" id="btn-new-vendor">
</form>
</div>
Go ahead and use that error as a response to work with in your app. You can add a begin/rescue/end block to your method:
# some code before
begin
DB.add_your_vendor_method
rescue
go_back_to_index
end
show_value_to_user
# some code after
You can make that block error specific, too. There is some nice write up on ruby error handling over at http://rubylearning.com/satishtalim/ruby_exceptions.html

Pass value between express routes

I have an html form in one of my views. One value in that form is a username. I gave that input an id.
<input name="username" class="form-control" id="username" placeholder="Username">
When the form is submitted, I redirect to a new view.
res.redirect('/nextView');
nextView has a javascript file being served to it from my public folder. In that javascript file, I am trying to access the username value like this:
$('#username').val()
This is not working. I think it's because now that I am on nextView, the id 'username' does not exist.
How can I persist this value from one view to the next?
You can redirect to a URL with a query parameter attached or save a cookie value.
To attach a query parameter:
res.redirect('/nextView?userName=' + username)
To read from a query parameter in the browser use a queryParam parser. Example

flask - user input (login/password) to a python variable

I'm trying to learn about login/password/user session stuff in flask.
i found this link and have been trying to understand the code it provides (on the bottom of the page, the largest piece of code).
http://thecircuitnerd.com/flask-login-tokens/
The link doesn't provide, though, the contents of the login.html file.
So far, the way i've been handling forms in flask requires me to specify to the render_template function what user input will be attributed to each python variable. But since the author didn't do it, i suppose his method of getting the user input should be different than that.
If you look at the login route handler in the code you linked you'll see that it uses request.form to get out two variables, 'username' and 'password':
#app.route("/login/", methods=["GET", "POST"])
def login_page():
"""
Web Page to Display Login Form and process form.
"""
if request.method == "POST":
user = User.get(request.form['username'])
#If we found a user based on username then compare that the submitted
#password matches the password in the database. The password is stored
#is a slated hash format, so you must hash the password before comparing
#it.
if user and hash_pass(request.form['password']) == user.password:
login_user(user, remember=True)
return redirect(request.args.get("next") or "/")
return render_template("login.html")
The simplest way to do this would be with the following HTML:
<form action="/login/" method="POST">
<input name="username" placeholder="username">
<input type="password" name="password" placeholder="password">
<input type="submit" value="Login">
</form>
This will not re-populate the username if the user mis-types their username or password, nor will it give the user any indication that they failed to login. They will just see the login form again. However, this is just some example code, so it's understandable that the author chose to leave out useful code that would obscure the point he was trying to make.