Add id attribute to a link in draftjs - draftjs

I need to add 'id' attribute to an anchor created using draft-js createEntity.
This is what I tried:
const contentState = editorState
.getCurrentContent()
.createEntity('LINK', 'MUTABLE', { url, id: 123 });
The link is created but it doesn't get the id.
Can anyone help?

Related

Set ag grid readonly fields

I am using a method per ag-grid example setting
gridOptions = {
columnDefs: [],....etc.
and reading a json file from the server that populates the fields (and columns).
// Get data from server //https://ag-grid.com/javascript-data-grid/getting-started/
fetch ('https://dev.perfectiononwheels.com/pricedataJSON/pricelistJson.json')
.then(function (response) {
return response.json();
}).then(function (data) {
// set the column headers from the data
const colDefs = gridOptions.api.getColumnDefs();
colDefs.length=0;
const keys = Object.keys(data[0])
keys.forEach(key => colDefs.push({field : key}));
gridOptions.api.setColumnDefs(colDefs);
// add the data to the grid
gridOptions.api.setRowData(data);
});
The document states that using this technique you can then set editable:true to be able to edit fields on the grid. However, I would like to set some columns (fields) as read-only, and change another to a checkbox.
I am not able to find an refernce on how to access a column to change to read-only or a checkbox.
(I was able to set these params when I defined each field in the columnDefs)
There is no direct api for this.
To change whether a column is editable, you'll have to change the editable property for the column in the columnDefs, and then call the grid api's setColumnDefs() method, passing it the updated columnDefs.
Same thing with the checkboxSelection property, to show a checkbox or not.

react-bootstrap-typeahead: How to get attribute value on "OnChange" , I am using Typeahead in table cell

I am using react-bootstrap-typeahead in table row for invoice items.
my json is like [{record_id:1,value="value1"},{record_id:2,value="value2"}]
on this basis I am creating bootstrap table.
in table cell I am adding typeahead select box to change the value and update my json,
when I change the value I want to update my json array with latest value in related record.
But as in onChange we only get selected array not an event object so, I am not able to find record id.
I have create one solution , I know it is not best but it works for me.
I have set state called currentLineItem and I am updating this value on "onFocus" event of react-bootstrap-typeahead. in this event I am getting an event object.
const [currentLineItem, setCurrentLineItem] = useState(null);
const selectBoxOnFocus = (event) => {
const rowId = event.target.parentNode.parentNode.parentNode.parentNode.getAttribute("data-id");
setCurrentLineItem(rowId);
};
const taxCalcChangeInRow = async (option) => {
const rowId = currentLineItem;
// my other code
};
<SelectBox {/*(this is wrapper componat of typeahead)*/}
data-id={row.id}
name="inputTaxCalc"
options={taxCalcOptions}
OnChange={taxCalcChangeInRow}
onFocus={selectBoxOnFocus}
/>

Firestore: set post id

How can I set id of post that I'm adding? I thought that getItemNextKey() returns id that will be assigned for the post, but it's not.
AddItem(data, downloadURLs) {
data.id= this.getItemNextKey(); // Persist a document id
data.upload = downloadURLs;
// console.log('this.uploadService.downloadURLs: ' + downloadURLs);
// console.log('data.upload: ' + data.upload);
this.db.collection('items').add(data);
}
I did this and it works now.
// Add a new document with a generated id
var addDoc = this.db.collection('items').add(data).then(ref => {
var updateNested = this.db.collection('items').doc(ref.id).update({
id: ref.id
});
});
As stated in the official docs
When you use set() to create a document, you must specify an ID for
the document to create. For example:
db.collection("cities").doc("new-city-id").set(data);
If you dont want to set an ID yourself you can use add
But sometimes there isn't a meaningful ID for the document, and it's
more convenient to let Cloud Firestore auto-generate an ID for you.
You can do this by calling add():

Mongoose - Restrict the fields on referenced model

I have users model that can hold multiple notifications. In the NotificationSchema the notifier holds users ID and it references the users model. When I execute the following query :
User.find().populate('notifications.notifier').exec(function(err,users){
//users[0].notifications[0].notifier
//I am getting all fields from the referenced user
//I don't want the whole document but some fields only
});
How can someone Limit / Restrict the fields that should be available while referencing to some model.
Here is the users model
var NotificationSchema =new Schema({
notifier : {type:Schema.Types.ObjectId, ref:'users'},
//How could I say :
//notifier : {type:Schema.Types.ObjectId, ref:'users', fields:['_id', 'name']}
//because I know what fields do I need from referenced model for this Schema.
__SOME__
__OTHER__
__FIELDS__
});
var UsersSchema = new Schema({
name : {given:String, middle:String, family:String}
email:String,
password:String,
notifications : [NotificationSchema]
});
var Users = mongoose.model('users', UsersSchema);
BTW, I do not have separate model for NotificationSchema.
If this feature is not available out of the box how could I implement it manually. Am I missing some docs? Please let me know the robust way of doing it.
I found it in mongoose docs
I found the answer in Field Selection Section of the documentation
User.find().populate('notifications.notifier', '_id name').exec(function(err, users) {
//users[0].notifications[0].notifier ^^^^^^^^^ HOW FUNNY
//Yes I am getting '_id' and 'name' fileds only
});

ASP.NET MVC Multiple File Uploads

I'm working on a strongly-typed edit form for a MVC model that contains a collection of child models (Document contains many LocalizedDocuments). Each document can contain 0, 1, or many localized documents, and every localized document has an input type="file" to allow the user to upload a new version of the file.
To render the edit fields for each LocalizedDocument I have a strongly-typed partial view that contains the fields for the LocalizedDocument, and then in my edit view use Html.EditorFor(model => model.Document.LocalizedDocuments).
When the form is posted, each of my LocalizedDocument fields are prefixed with LocalizedDocument[i], as expected. However, how can I get it so the file input is also prefixed with LocalizedDocument[i], so I can relate the file upload to the appropriate LocalizedDocument?
Tell me if I'm interpreting this question wrong. You have documents that you need to upload that belongs to a parent table or you need to assign these documents a specific id after uploading multiple of them?
I'll be using Uploadify.
You will have to know the Id of the LocalizedDocument. You will also only be able to upload 1 at a time. (each file is a separate server call)
First you have to assign the Id of the LocalizedDocument to the data that will be sent to the server.
<script type="text/javascript">
var auth = "<%: Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>";
var ASPSESSID = "<%: Session.SessionID %>";
$(document).ready(function () {
$('#file_upload').uploadify({
'uploader': '/Content/uploadify.swf',
'script': '<%: Url.Action("Upload", "Documents") %>',
'cancelImg': '/Content/Images/cancel.png',
'folder': '/uploads',
'scriptData': { ASPSESSID: ASPSESSID, AUTHID: auth, DocumentId: <%: Model.LocalizedDocumentId %>},
'auto':true,
'multi': true
});
});
</script>
Controller:
public ActionResult InsertImages(HttpPostedFileBase FileData, int DocId){ }