I don't know if it is possible, but I like to show a picture after uploading it into the Library.
As soon as I want to cascade the serializeFileUpload I get an error and the method comment also states that serializeFileUpload may be the only callback.
My code so far:
html fileUpload
...
id: #fileUpload;
onChange: (html jQuery ajax
serializeFileUpload: (html jQuery id: inputString ));
callback: [ :f | self handleNewFile: f]
Is there a way to have the jQuery replace #fileUpload with the uploaded image?
Thanks
Max
Implementation in JQAjax>>serializeFileUpload:aQuery
self
data:
((((JSStream on: 'var formdata = new FormData()'),
((aQuery copy attributeAt: 'name') assignLocalTo: 'name'),
(((aQuery property: 0) access: 'files') assignLocalTo: 'files'),
(JSStream on:'for(i=0;i<files.length;i++) formdata.append(name,files[i])'),
(JSStream on: 'return formdata')) asFunction) apply: #());
url: self renderContext actionUrl;
type: 'POST';
cache: false;
processData: false;
contentType: false
Have you tried to use the ajax onsucces callback?
(html jQuery ajax
...
onSuccess: ((html jQuery id: #fileUpload) replaceWith: [:r | ... ]))
Related
How do I get an element's inner HTML from an elementId using browser object?
Is there something like elementIdHtml available in the WebdriverIO API?
The getHTML link for v4 is returning 403 Forbidden.
my goal is that i need to get all text inside all a._3cnp from an elementId
example html
<div class="container">
<a class="_3cnp">first link</a>
<a class="_3cnp">second link</a>
<a class="_3cnp">third link</a>
</div>
need to convert that to ["first link", "second link", ..]
i have the .container elementId already
this is what i did
.then(() => browser.elementIdElements(someElementId, 'a._3cnp'))
.then(buttonElem => {
console.log('->', buttonElem)
console.log('-->', buttonElem.getHTML)
buttonElem.getHTML().then(x => console.log('---->', x))
return buttonElem.value
})
result of elementIdElements is
buttonElem
{ sessionId: '2e2f144c8895a03da1b8df92f4613a33',
status: 0,
value:
[ { ELEMENT: '0.6603119466268468-24',
'element-6066-11e4-a52e-4f735466cecf': '0.6603119466268468-24' } ],
selector: 'a._3cnp' }
but buttonElem.getHTML is undefined
im using webdriverio standalone from botium-webdriverio-connector
LE:
Change your code accordingly to the following:
.then(() => browser.elementIdElements(someElementId, 'a._3cnp'))
.then(buttonElem => {
// buttonElem's 'value' will contain a list of all the matching elements
// thus, you have to call getHTML() on each item from 'value'
// the following will return the HTML of the first matching element
console.log('\nPrint element HTML: ' + buttonElem.value[0].getHTML());
return buttonElem.value[0].getHTML();
})
A better approach would be to loop between them & print the HTML:
.then(() => browser.elementIdElements(someElementId, 'a._3cnp'))
.value.forEach(buttonElem => {
console.log('\nPrint element HTML: ' + buttonElem.getHTML());
return buttonElem.getHTML();
})
The .getHTML() property is scoped to all the ELEMENT objects. For the sake of more didactical approach, I'm going to consider the task to be manipulating the HTML code found in a series of list items (<li>), from am unordered list (<ul>).
So you can do the following:
browser.getHTML('ul.ourList li.ourListItems') (this will return a list of all the <li>'s HTML code)
browser.element('ul.ourList li.ourListItems').getHTML() (this will return the first <li>'s HTML code)
$('ul.ourList li.ourListItems').getHTML() (this is the equivalent of the command above, only a relaxed version)
If you need to iterate through all the <li>s & get the HTML, do this:
let locator = 'ul.ourList li.ourListItems';
browser.elements(locator).value.forEach(elem => {
let elemHTML = elem.getHTML();
console.log( JSON.stringify(elemHTML) );
elemHTML.doSomethingWithIt();
})
where, elem will is an object with the following format:
{ ELEMENT: '0.285350058261731-1',
'element-6066-11e4-a52e-4f735466cecf': '0.285350058261731-1',
selector: 'ul li.fw-item.fz-16.lh-36.pos-r',
value: { ELEMENT: '0.285350058261731-1' },
index: 0
}
I'm using Alamofire.upload to upload an image as a .POST multipart to my server. But my server always gets parameters only as a query string, and use multipart only for a file data. So in my request I also need to put some parameters to URL, but it seems Alamofire.upload have't a variant with parameters argument.
Alamofire.upload(
.POST,
"https://httpbin.org/post?user=\(userId)&photo=\(photoTitle)",
multipartFormData: { multipartFormData in
multipartFormData.appendBodyPart(fileURL: unicornImageURL, name: "unicorn")
},
encodingCompletion: nil
)
For now I just put all parameters by myself directly forming request-string: "https://httpbin.org/post?user=\(userId)&photo=\(photoTitle)".
Is there a better way to pass query parameters to Alamofire.upload?
What can do things better is Alamofire.ParameterEncoding, but it will need some workaround with requests.
var req: NSMutableURLRequest?
(req!, _) = Alamofire.ParameterEncoding.URL.encode(
NSURLRequest(URL: NSURL(string: "https://httpbin.org")!),
parameters: ["user": userId, "photo": photoTitle]
)
Alamofire.upload(
.POST,
req!.URLString,
multipartFormData: { multipartFormData in
multipartFormData.appendBodyPart(fileURL: unicornImageURL, name: "unicorn")
},
encodingCompletion: nil
)
I have this jquery code:
$("#tf_zoom").live("click", function () {
var n = $(".tf_thumbs").find("img").attr("src");
var modelid = n.substr(43);
$.post("models/get_gallery", {
"modelid": modelid
}, function (data) {
var imagespathes = $(data).map(function (key, url) {
return ({
href: '<?php echo base_url();?>assets/uploads/files/' + url
});
});
console.log(imagespathes);
$.fancybox.open(imagespathes);
}, "json");
});
and this is my html:
<div id="tf_thumbs" class="tf_thumbs">
<span id="tf_zoom" class="tf_zoom"></span>
<img id="dynam" src="<?php echo base_url();?>assets/uploads/files/<?php echo $firstthumb;?>" alt="Thumb1"/>
</div>
Okay, now my problem is that this code is not functioning on IE 10 and surprisingly it's working like a charm on IE 9, IE 8, IE 7 besides FF and Google Chrome
I read many things about this issue but nothing worked for me.
So, is there any solution for it.
your help is really appreciated.
Update 1 : I am using jquery version 1.7
Perhaps this hint will help you:
I have noticed that .map( $("select").get(0).options ) will not work in IE10 but .map( $("select:first >option") ) will. This is because in ie10 .options returns a select node with an iteration of options.
So see what data is returning in IE10, perhaps it too is not an array. And if so perhaps you can do something like $(new Array(data)).map(... which will satisfy all browsers
You should be using static map function for this:
$.map(data, function(obj, index){...})
See documentation here.
// If data looks like this: [{ url: 'TestUrl' }]
// This should work:
var imagespathes = $.map(data, function(element){
return { href: '<?php echo base_url();?>assets/uploads/files/' + element.url };
});
Hi as the Title says i am getting this error suddenly without changing anything.
This is the File Locations Code:
Ext.define('Wickelplaetze.store.Locations', {
extend: 'Ext.data.Store',
requires: 'Wickelplaetze.model.Location',
config: {
model: 'Wickelplaetze.model.Location',
storeId: 'locationsstore',
grouper: {
groupFn: function(record) {
return record.get('ort').substr(0, 1);
},
sortProperty: 'ort'
},
proxy: {
type: 'ajax',
url: 'http://freakp.com/wpapp/form-data.json',
withCredentials: false,
useDefaultXhrHeader: false
},
autoLoad: true
}
});
There are null values in you json for key ort. You can check if ort is not null and then return like -
if(record.get("ort")!= null){
return record.get('ort')[0];
}
Will remove that error doing so. But this will not sort records properly.
One more thing, if you want to sort list by first letter of ort , you can directly use -
return record.get("ort")[0];
When I tried your code to populate list, its actually running infinitely. I didn't get anything. Sorting these much values is damn slow. It took 3 mins to populate the list.
UPDATE
Link for working fiddle for your example. You can see null values at bottom of list. There are 7 null values for key ort.
This is a Noob question regarding Backbone.JS and ActiveRecord.
I'd be grateful for a pointer on how to debug this.
I'm trying to use Backbone.Js code to create a "Trainer" object, which has a single attribute, "name" (a string).
The front end of the application is Ruby on Rails. There is a data migration for the Trainer table.
In trainers controller:
def create
document = Trainer.create! params[:trainer]
render :json => document
end
Now, in app/assets/javascripts/backbone/views/trainers/new_view.js:
Gym.Views.Trainers.NewView = Backbone.View.extend({
el : 'div.trainer_form',
template: JST['backbone/templates/trainers/new_template'],
model : new window.Gym.Models.Trainer({}),
initialize: function() {
this.document = this.options.user;
Backbone.Validation.bind(this, {
invalid: function(view, attr, error) {
$("form#new-trainer .errors ul").append("<li>" + error + "</li>")
}
});
this.render();
},
render : function() {
$(this.el).html(this.template({trainer:this.model.toJSON()}));
return this
},
events : {
"click input#submit_button" : 'create_trainer'
},
create_trainer : function(event) {
event.preventDefault()
params = $("form#new-trainer").formParams()
params['user_id'] = Gym.currentUser.userId
this.model.save(params, {success : function(model, response) {
Gym.trainers.add(model)
Objects.views.selectTrainer.render()
Gym.current_trainer = model
$("select#trainer_selector").val(Gym.current_trainer.get('id'))
Objects.views.new_trainer.model = new Gym.Models.Trainer()
Objects.views.new_trainer.render()
}
});
Now, I can see in the Rails log that I'm getting to the controller:
Started POST "/trainers" ...
Processing by TrainersController#create as JSON
Parameters: {"name"=>"Lori Stevens", "user_id"=>1, "trainer"=>{}}
However, when it gets to the SQL, I see this:
[1m^[[36mSQL (0.4ms)^[[0m ^[[1mINSERT INTO `trainers` (`created_at`, `name`, `updated_at`, `user_id`) VALUES ('2012-11-07 20:33:09', NULL, '2012-11-07 20:33:09', NULL)^[[0m
The parameter 'name' - which comes from the template, and is the attribute of the Trainer object- is not getting to the database, even though the parameter "name" is set in the JSON.
I'd appreciate a pointer on how to debug this - clearly I am not understanding how Backbone.js and ActiveRecord are connected.
The Controller takes the request from your browser and puts the data into ActiveRecord:
def create
document = Trainer.create! params[:trainer]
...
end
But then you see request in the log, params[:trainer] equals the empty hash {}
You can either change the javascript that it creates json with a hash like
{ 'trainer': {'name' : 'Lori stevens', ... }}
I don't know how easy this in backbone.
Or you can change your controller that it gets the values out of the hash and constructs an new hash for your trainer model, like it is:
gotten_name_from_json = params['name']
...
document = Trainer.create!(
{:name => gotten_name_from_json, :town => gotten_twon_from_json})
I made this verbose to show that using this you can translate what ever json comes in, even when it comes from third parties where you can not control the format.