I am not sure what it is called, but I want to be able to click on e.g. a div
containing a number, and then it will change into a input text field, with the value being the number I clicked.
Then I want to edit the number, and click off (onblur
event), and it will change back to a div
, from the text field showing the new edited number. The number would have also been updated into the database via ajax.
What is this function called?
What is the best way to code this?
Inline Edit in a FormClick the text or edit button to make the field editable. If the text is a link, the user must click the edit icon to make the field editable. Select: If the user clicks and holds, they should be able to select the text rather than transition into the edit mode.
Inline Editing is a feature that allows users to seamlessly edit and write content visually and directly on-screen without having to toggle between a 'read-only' view and an 'edit' view. In short, users can make quick changes or create content without going to a new page.
What is Inline Editing in Salesforce? Inline editing is the ability to change the value of a field, without needing to navigate to a record. Inline editing means being able to update a record from somewhere other than the record page, such as a list view or report.
I know this is an old thread, but I built a project that does exactly this a while ago: https://github.com/JackChilds/Preview-In-Place.
You can then use it like this:
// get element:
var el = document.querySelector('#idOfElement')
// function to process the user's data, e.g. you could convert markdown to HTML here:
function processData(data) {
return data.toUpperCase() // do something with the data here
}
// initialise the class:
var example = new PreviewInPlace(el, {
// options
previewGenerator: processData // reference to the function that processes the data
})
<div id="idOfElement" class="block">
<textarea class="edit">Some Text Here</textarea>
<div class="preview"></div>
</div>
<script src="https://cdn.jsdelivr.net/gh/JackChilds/Preview-In-Place@main/dist/previewinplace.min.js"></script>
And of course you can add some CSS to make it look a bit neater:
// get element:
var el = document.querySelector('#idOfElement')
// function to process the user's data, e.g. you could convert markdown to HTML here:
function processData(data) {
return data.toUpperCase() // do something with the data here
}
// initialise the class:
var example = new PreviewInPlace(el, {
// options
previewGenerator: processData // reference to the function that processes the data
})
.block {
width: 200px;
}
.block .edit {
border: none;
outline: none;
border-radius: 0;
resize: none;
}
.block .edit, .block .preview {
padding: 8px;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
/* Make the 'block' have a red background when in edit mode */
.block.state-edit .edit {
background-color: rgba(131, 0, 0, 0.3);
}
/* Make the 'block' have a green background when in preview mode */
.block.state-preview .preview {
background-color: rgba(9, 174, 0, 0.3);
}
<div id="idOfElement" class="block">
<textarea class="edit" rows="1">Some Text Here</textarea>
<div class="preview"></div>
</div>
<script src="https://cdn.jsdelivr.net/gh/JackChilds/Preview-In-Place@main/dist/previewinplace.min.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With